Visitar URL original
fix(keep_names): don't emit class static blocks for targets without them by thelastbackspace · Pull Request #11497 · rolldown/rolldown · GitHub
Skip to content

fix(keep_names): don't emit class static blocks for targets without them - #11497

Open
thelastbackspace wants to merge 2 commits into
rolldown:mainfrom
thelastbackspace:fix/11469-keep-names-static-block-target
Open

thelastbackspace wants to merge 2 commits into
rolldown:mainfrom
thelastbackspace:fix/11469-keep-names-static-block-target

Conversation

@thelastbackspace

Copy link
Copy Markdown

Fixes #11469

When keepNames needs to restore a class name, the finalizer injects static { __name(this, "Foo") }. That runs after the transform step, so it never gets lowered, and a build with transform.target: 'es2018' ends up with ES2022 syntax in it.

If the target doesn't support class static blocks (ESFeature::ES2022ClassStaticBlock), the helper now goes outside the class body, the same way it already does for functions:

  • class declarations: __name(Foo$1, "Foo") goes right after the declaration (using the existing keep_name_statement_to_insert path)
  • anonymous class expressions, export default class {} and export default (class {}): /* @__PURE__ */ __name(class {}, "Foo")

Targets that do support static blocks get the same output as before.

For export default class {} I build var default = __name(class {}, "default") directly rather than queueing a statement. The queued position is computed before the walk, and visit_statements inserts its own statements first, so the position would be stale whenever the module also has a renamed class or function declaration earlier on.

Added keep_names/unsupported_class_static_block (target es2018). It covers a renamed declaration, an anonymous class expression, a self-referencing class, a nested class, and the three default-export shapes. Without the fix the snapshot has six static { blocks. With it there are none, and the name asserts still pass when the output runs.

@codspeed

codspeed Bot commented Nov 5, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 4 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 7 untouched benchmarks
⏩ 10 skipped benchmarks1


Comparing thelastbackspace:fix/11469-keep-names-static-block-target (314c551) with main (048642a)2

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. ↩

  2. No successful run was found on main (38c68c2) during the generation of this report, so 048642a was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@hyfdev hyfdev self-assigned this Nov 11, 2026

This branch has not been deployed

No deployments
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.

[Bug]: keepNames emits class static blocks despite an ES2018 target

2 participants