Skip to content

fix(transform): transformer gate skips newer syntax that oxc can lower - #10564

Merged
IWANABETHATGUY merged 4 commits into
rolldown:mainfrom
sekyungk:fix/transform-gate-using-syntax
Jul 31, 2026
Merged

IWANABETHATGUY merged 4 commits into
rolldown:mainfrom
sekyungk:fix/transform-gate-using-syntax

Conversation

@sekyungk

@sekyungk sekyungk commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Run the Oxc transformer for JavaScript files when the target lacks Explicit Resource Management (using declarations).
  • Simplify should_transform_js(). Its Normal/Raw arms always returned the same result. Now it checks self.target directly.
  • Add an es2024 regression fixture.

Problem

should_transform_js() only checked whether the target needed Unicode Sets RegExp transformed. Targets such as Chrome 133 support Unicode Sets RegExp but not Explicit Resource Management, so the transformer never ran and using declarations were emitted unchanged. To fix this, it now also checks whether the target needs Explicit Resource Management lowered.

Along the way, should_transform_js() itself is cleaned up. The env flags that the Normal variant used to read are computed from the same target by oxc's EnvOptions::from(EngineTargets) via has_feature(), so they always agree with the Raw variant's self.target.has_feature() checks by construction (tsconfig merging never touches target). The per-variant branching is replaced with a single expression over self.target.

The new es2024 fixture verifies that using is lowered through the default build path.

AI usage

Drafted with Codex and double-checked with Claude. I reviewed and verified all changes myself.

@sekyungk
sekyungk force-pushed the fix/transform-gate-using-syntax branch from aae9ade to 2334259 Compare July 31, 2026 09:40
@sekyungk
sekyungk marked this pull request as ready for review July 31, 2026 10:33
@codspeed

codspeed Bot commented Jul 31, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 7 untouched benchmarks
⏩ 10 skipped benchmarks1


Comparing sekyungk:fix/transform-gate-using-syntax (e57e0de) with main (347cb3b)

Open in CodSpeed

Footnotes

  1. 10 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@sekyungk sekyungk changed the title fix(transform): transformer gate stuck at unicode-sets regex skipped newer syntax fix(transform): transformer gate stuck at unicode-sets regex, skipping newer syntax Jul 31, 2026
…ture

`should_transform_js` named two ES features, so it answered correctly only
where those two happened to subsume the rest. That is what let `using`
declarations through on an `es2024` target, and any future oxc lowering
reopens the same hole.

Decide it from `LOWERABLE_ES_FEATURES` instead — the full set oxc's
`impl From<EngineTargets> for EnvOptions` turns into transform flags. The
ES2025 RegExp features stay out on purpose: oxc knows them but cannot lower
them, so listing them would buy a transform pass that cannot change anything.

Precompute the answer in the constructors. The widened list walks oxc's
static feature table once per entry (a `OnceLock` load, a hash into the
feature map, then a lookup per engine in it) and `PreProcessEcmaAst` reads
it once per JS module, so computing it on demand is no longer cheap.

`tests::env_lowers_anything` destructures `EnvOptions` and every ES-edition
group exhaustively, so an oxc upgrade that adds a group stops compiling
until the list is revisited. `RegExpOptions` lives in a private oxc module
and cannot be named in a pattern, so its flags are read field by field and
a brand new RegExp lowering would still slip past.

Two fixtures cover what the es2024 one cannot: `chrome133` for the engine
target path (it ships unicode-sets RegExp but not `using`, and engine
targets do not reduce to a single ES version), and `tsconfig: false` for the
`Normal` transform-options variant — tsconfig defaults to auto-discovery, so
every other fixture exercises `Raw`.
@netlify

netlify Bot commented Jul 31, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for rolldown-rs canceled.

Name Link
🔨 Latest commit e57e0de
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/6a6cc26e6d50430008da36e4

@IWANABETHATGUY

Copy link
Copy Markdown
Member

I’ll make a few small changes directly on your branch to avoid unnecessary back-and-forth and help move this forward more efficiently.

@IWANABETHATGUY

Copy link
Copy Markdown
Member

Nice find — this is a real bug, and the reasoning in the description holds up. I checked the chain you assert: BundlerTransformOptions has no env field, TryFrom derives env from options.target via EnvOptions::from_target (which is literally EngineTargets::from_target(s).map(Self::from)), prepare_build_context.rs builds TransformOptions.target from the same string, and tsconfig_merge.rs only ever reads compilerOptions.target for useDefineForClassFields. So the two variants really do agree by construction — the unification is sound, not just plausible.

I also confirmed your fixture is a genuine regression test: reverting only should_transform_js to the old body flips the snapshot back to raw using resource = acquireResource();.

Since maintainer edits are on, I pushed one commit (000d621) rather than round-tripping review comments. Happy to drop or rework any of it — details below.

1. Derive the gate from every lowerable feature

The two-feature check is correct today, but only by accident of ordering: unicode-sets is ES2024, so for pure ES targets it subsumes every older lowering, and ERM is the newest thing oxc can lower. EnvOptions has ~20 flags and the gate named 2 of them, so the next oxc release that gains a lowering silently reopens exactly this bug — and nothing in the type system or the test suite would catch it.

It now derives from LOWERABLE_ES_FEATURES, the full set oxc's impl From<EngineTargets> for EnvOptions turns into transform flags. The ES2025 RegExp features stay out deliberately: oxc knows them but has no transform option for them, so listing them would buy a pass that cannot change anything.

The guard against this rotting again is tests::env_lowers_anything, which destructures EnvOptions and every ES-edition group exhaustively — when an oxc upgrade adds a group, as ES2026 once was, it stops compiling. One gap I could not close: RegExpOptions lives in a private oxc module, so it cannot be named in a pattern and its flags are read field by field. A brand-new RegExp lowering would still slip past. Noted in place.

Verified the test bites: dropping ES2026ExplicitResourceManagement from the list fails on es2024.

2. Precompute it

Two reasons. The widened list walks oxc's static feature table once per entry — a OnceLock load, a hash into the feature map, then a map lookup per engine inside it — and PreProcessEcmaAst asks this once per JS module. Separately, on main the Normal arm was a single bool field read (opts.env.regexp.set_notation), and this PR turned it into two has_feature calls; small, but it was a step backwards on the hot path.

It is now a bool computed in new/new_raw/Default, so the per-module cost is a field read again and widening the list costs nothing at runtime.

3. Two more fixtures

One correction to something I initially got wrong: TsConfig::default() is Auto(true), so your es2024 fixture is already exercising the Raw variant — Normal was the untested one. Added tsconfig: false to cover it.

Also added chrome133, which is the case your own description leads with but that nothing tested. It is worth pinning separately: engine targets do not reduce to a single ES version, so they take a different path through has_feature, and it is the shape a real Vite/browserslist config produces. I confirmed it lowers correctly.

Both are genuine regression tests — with the pre-PR gate restored, all three fixtures emit raw using.

Verification

  • cargo test --workspace: 1952 passed. The 5 failures are environmental in a fresh worktree (4 need node_modules, 1 needs the test262 submodule), not snapshot mismatches — so the widened list shifted no existing output.
  • cargo fmt --check, cargo clippy --workspace --all-targets -- --deny warnings, cargo check --workspace --all-targets all clean.
  • Only 4 in-repo fixtures set transform.target (es6/es2015/es2018/es2021), all already below the old gate, which is why nothing else needed a snapshot update.

Two notes, neither blocking

The description has an inverted sentence. "Check whether the target supports Explicit Resource Management" — has_feature returns true when the feature is not supported (needs transformation); its own doc comment says so. The code is right, the prose reads backwards. Only you can edit the description, so flagging rather than fixing.

An upstream gap worth knowing about: target: "safari18" does not lower using. oxc's ES2026ExplicitResourceManagement entry lists only {Chrome 134, Node 24, Firefox 141, Edge 134, Es 2026} — no Safari, iOS, or Samsung — so has_feature falls through to the Es default and reports it supported. Safari did not ship ERM until 26.0. Out of scope here, since EnvOptions is built from the same call and the transformer would not lower it either way, but it means the fix does not reach those targets. Probably worth an oxc issue.

@sekyungk sekyungk changed the title fix(transform): transformer gate stuck at unicode-sets regex, skipping newer syntax fix(transform): transformer gate skips newer syntax oxc can lower Jul 31, 2026
@sekyungk sekyungk changed the title fix(transform): transformer gate skips newer syntax oxc can lower fix(transform): transformer gate skips newer syntax that oxc can lower Jul 31, 2026
@sekyungk

sekyungk commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor Author

@IWANABETHATGUY

I appreciate your sincere comments and ongoing feedback.

I just revised the sentences. I apologize for not addressing the meaning clearly.
As this commit has significantly changed the entire implementation of this PR, would it be better if I update the PR description to relate the final implement?
Regarding this project, I'm fully open to whatever you prefer. Just feel free to let me know.

I was also aware of the fragility of the feature enumeration — I went with minimal hardcoding because oxc has no API to ask whether a target needs any lowering.
Keeping the list but enforcing updates at compile time with env_lowers_anything - I think I should learn this.

On the Safari gap: I had run into the same thing while verifying the oxc compat data — the ES2026ExplicitResourceManagement entry has no Safari/iOS, and it's still missing on oxc's latest main.
I'll open a separate PR to oxc for it.

It took time as I'm not get used to express something in English.
Thank you.

@sekyungk

sekyungk commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor Author

@IWANABETHATGUY oxc-project/oxc#25155 I just checked the PR you opened on oxc. Seems I was a bit late this time. Thanks a lot.

@IWANABETHATGUY
IWANABETHATGUY merged commit 11e008b into rolldown:main Jul 31, 2026
34 checks passed
@IWANABETHATGUY

Copy link
Copy Markdown
Member

@IWANABETHATGUY

I appreciate your sincere comments and ongoing feedback.

I just revised the sentences. I apologize for not addressing the meaning clearly. As this commit has significantly changed the entire implementation of this PR, would it be better if I update the PR description to relate the final implement? Regarding this project, I'm fully open to whatever you prefer. Just feel free to let me know.

I was also aware of the fragility of the feature enumeration — I went with minimal hardcoding because oxc has no API to ask whether a target needs any lowering. Keeping the list but enforcing updates at compile time with env_lowers_anything - I think I should learn this.

On the Safari gap: I had run into the same thing while verifying the oxc compat data — the ES2026ExplicitResourceManagement entry has no Safari/iOS, and it's still missing on oxc's latest main. I'll open a separate PR to oxc for it.

It took time as I'm not get used to express something in English. Thank you.

And don't read the extra commits as a knock on the PR. You found a real bug, diagnosed the cause correctly, and your instincts were right on both counts — that the enumeration was fragile, and that oxc's compat data was missing Safari. That's the hard part. Nice work.

IWANABETHATGUY added a commit that referenced this pull request Aug 3, 2026
… exists

The three `using` fixtures added in #10564 sit as siblings under `function/`,
distinguished only by a suffix on the directory name, and the first carries no
`_comment` — `"target": "es2024"` alone does not convey why that target in
particular.

Nest them under one group, following the `advanced_chunks/` convention where the
parent is a plain directory with no `_config.json` of its own, and name each leaf
after the case it pins rather than after how it differs from its neighbour:

  explicit_resource_management_target/
    es2024/              the ES-target gap the old gate fell through
    chrome133/           engine targets, which do not reduce to one ES version
    es2024_no_tsconfig/  the `Normal` transform-options variant

Each leaf gets a `_comment` explaining what it covers. Snapshots are unchanged —
their contents do not encode the fixture path.
IWANABETHATGUY added a commit that referenced this pull request Aug 3, 2026
… exists (#10569)

Test-only follow-up to #10564. No source changes, and the snapshots are
byte-identical — their contents do not encode the fixture path.

## What

The three `using` fixtures added in #10564 sat as siblings under
`function/`, told apart only by a suffix on the directory name:

```
explicit_resource_management_target/
explicit_resource_management_target_chrome/
explicit_resource_management_target_no_tsconfig/
```

They are now one group, following the `advanced_chunks/` convention
where the parent is a plain directory with no `_config.json` of its own,
with each leaf named after the case it pins rather than after how it
differs from its neighbour:

```
explicit_resource_management_target/
  es2024/              the ES-target gap the old gate fell through
  chrome133/           engine targets, which do not reduce to one ES version
  es2024_no_tsconfig/  the `Normal` transform-options variant
```

## Why

Two things the old layout left implicit.

The `es2024` fixture carried no `_comment`, and `"target": "es2024"`
alone does not explain why *that* target. It is the one that exposed the
bug: unicode-sets RegExp is supported from es2024 on, so a gate keyed on
that single feature concluded "nothing left to lower" — while `using` is
not supported until es2026 and does need lowering. Without the fix it
emits `using resource = acquireResource();` unchanged.

The `_no_tsconfig` comment said the variant differs from "every other
fixture", which was true while the three were scattered and misleading
once they are siblings. It now names what it actually pins: the same
`es2024` target on the `Normal` options variant, since `tsconfig`
defaults to auto-discovery and puts the other two on `Raw`.

Each leaf now carries a `_comment` saying what it covers.

## Test plan

- `cargo test -p rolldown --test integration` — 1971 passed, 0 failed
- The three fixtures pass at their new paths; no snapshot regeneration
was needed
@rolldown-guard rolldown-guard Bot mentioned this pull request Aug 3, 2026
shulaoda added a commit that referenced this pull request Aug 3, 2026
## [1.2.2] - 2026-08-03

### 🚀 Features

- code-splitting: support inlining of shared deps in dynamic entries (#10526) by @nicolo-ribaudo
- plugin: time the user callbacks configured on the options (#10509) by @IWANABETHATGUY

### 🐛 Bug Fixes

- dev: force `cleanDir` off in dev mode (#10579) by @shulaoda
- dev: keep `?rolldown-lazy` proxy ids out of user `resolveId` hooks (#10580) by @btea
- initialize re-exported wrapped ESM modules at the entry chunk (#10567) by @hyfdev
- link: resolve circular star reexports as null (#10445) by @Nic-Polumeyv
- transform: transformer gate skips newer syntax that oxc can lower (#10564) by @sekyungk
- code-splitting: materialize consumer-local barrel routing when the order-wrap plan is empty (#10544) by @hyfdev
- plugin: measure plugin hooks in JavaScript, report them from Rust (#10508) by @IWANABETHATGUY
- plugin: include external dynamic imports in chunk metadata (#10557) by @hyfdev
- plugin: report plugin timings after closeBundle has run (#10521) by @IWANABETHATGUY
- browser: avoid using node builtin modules (#10542) by @sapphi-red

### 🚜 Refactor

- plugin: give the build's own clocks their own type (#10520) by @shulaoda

### 📚 Documentation

- correct stale `buildStart` comment in `ScanStageCache::merge` (#10577) by @shulaoda
- update outdated pluginutils references (#10574) by @dogledogle

### ⚡ Performance

- external: drop the runtime import from chunks that never wrap (#10517) by @IWANABETHATGUY
- plugin: clock the build only when it is being measured (#10558) by @IWANABETHATGUY

### 🧪 Testing

- vite-tests: drop the dead `@rolldown/pluginutils` pnpm override (#10575) by @IWANABETHATGUY
- transform: group the transform-target fixtures and say why each exists (#10569) by @IWANABETHATGUY
- dev: fix hmr-hot-update-hook-vite fixture on Windows (#10565) by @h-a-n-a
- dev: match Vite's renamed full-reload log (#10547) by @shulaoda

### ⚙️ Miscellaneous Tasks

- deps: update napi (#10576) by @renovate[bot]
- deps: bump `@napi-rs/wasm-runtime` to 1.2.2 (#10570) by @shulaoda
- deps: update npm packages (#10583) by @renovate[bot]
- deps: update dependency rolldown-plugin-dts to ^0.28.0 (#10588) by @renovate[bot]
- deps: update taiki-e/install-action action to v2.85.5 (#10587) by @renovate[bot]
- deps: update codspeedhq/action action to v5 (#10584) by @renovate[bot]
- deps: update github actions (#10582) by @renovate[bot]
- deps: update rust crates (#10581) by @renovate[bot]
- deps: update dependency vite-plus to v0.2.7 (#10568) by @renovate[bot]
- deps: update dependency rolldown-plugin-dts to v0.27.14 (#10531) by @renovate[bot]
- deps: update pnpm to v11.17.0 (#10571) by @renovate[bot]
- deps: update @napi-rs/wasm-runtime to 1.2.1 (#10545) by @sapphi-red

### ❤️ New Contributors

* @sekyungk made their first contribution in [#10564](#10564)
* @nicolo-ribaudo made their first contribution in [#10526](#10526)

Co-authored-by: shulaoda <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants