Repository navigation
fix(transformer/typescript): preserve computed key context - #30148
Merged
Merged
Conversation
Contributor
Merging this PR will not alter performance
Comparing Footnotes
|
Dunqing
marked this pull request as ready for review
November 24, 2026 07:30
Dunqing
force-pushed
the
fix/typescript-computed-key-static-block
branch
2 times, most recently
from
November 24, 2026 09:55
7f51967 to
524ffba
Compare
Dunqing
force-pushed
the
fix/typescript-computed-key-static-block
branch
from
November 24, 2026 15:28
524ffba to
a81c69d
Compare
hoanle0126
pushed a commit
to hoanle0126/oxc
that referenced
this pull request
Nov 24, 2026
oxc-project#30184) A standard element decorator can inspect the class before its static blocks run. With `setPublicClassFields` enabled, it can see the symbol-keyed method that oxc-project#30148 generates to evaluate a computed key. The source class has no such property. ### Example ```ts const observed = []; function inspect(getClass) { observed.push(Object.getOwnPropertySymbols(getClass()).filter(key => key !== Symbol.metadata)); } function* make() { return class C { @inspect static getClass() { return C; } static [yield "key"] = 1; }; } const it = make(); expect(it.next().value).toBe("key"); const C = it.next("x").value; expect(C.x).toBe(1); expect(observed).toEqual([[]]); ``` The Oxc playground cannot run the downstream decorator pass that exposes the extra symbol. To print the JavaScript locally, save the input as `/tmp/repro.ts` and run the transformer example with the fixture options. ```sh fixture=tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/oxc/preserved-class-context-dependent-computed-keys cargo run -p oxc_transformer --example transformer -- /tmp/repro.ts --babel-options "$fixture/options.json" ``` Before, the generated method and cleanup were visible in the output. ```js static { delete this[_computedKey]; } // … static [(_yield$key = yield "key", _computedKey)]() {} ``` After, the key runs in a decorator expression on a private method. ```js @(_yield$key = yield "key", () => {}) static #_computedKey() {} ``` The generator still yields `"key"`, and the static field receives `1`. With Babel 2023-11 and esbuild, the inspecting decorator saw one extra symbol before and zero after. The runtime fixture also exercises a user-defined symbol and enclosing private names accessed directly and through `eval`. ```sh cargo run -p oxc_transform_conformance -- --filter /downstream-decorators/ --exec ``` The focused runtime result is `Passed: 1 of 1`. Transformer tests and lint passed. Transformer coverage snapshots matched, and full transform conformance recorded one additional passing Oxc exec fixture. AI disclosure: prepared with AI assistance. The exact model version and reasoning effort were not recorded.
Dunqing
added a commit
to rolldown/rolldown
that referenced
this pull request
Nov 24, 2026
Pins the restacked decorators-lowering head, now on oxc main 1abb96db. Snapshot changes: - Legacy decorator fixtures pick up main's fixes: computed and assigned keys are passed to __decorate instead of null, and decorated static fields keep their decorators (oxc-project/oxc#29979, oxc-project/oxc#30148, oxc-project/oxc#30184). - Generated calls whose callee has no source position now map to the call itself, so wrapped require(), init_*() and (0, x.f)() calls point at their source call rather than a neighbouring token. - _decoratorStart and _decorateElement now map to the class and to each decorated element, so a throwing decorator's frame lands on it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Computed class keys that depend on the surrounding context can be moved into a static block when
setPublicClassFieldsis enabled. For example, movingyieldmakes the output invalid; movingthiscan change the key. Oxc #29930 exposed this path for classes with preserved decorators or auto-accessors.Example
Input (playground for this example; the playground uses the released Oxc version):
With target ES2021 and
setPublicClassFields: true, the Rolldown bundle using Oxc before this change contains:The fixed Oxc transform produces (captured from the transformer with target ES2021,
set_public_class_fieldsandremove_class_fields_without_initializerenabled):A moved key already runs in place when a later computed key stays in the class, because it is prepended to that key. Only the keys after the last one went into the leading static block. When one of those keys uses
this,super,arguments,new.target,yield,awaitor directeval, they now go into the key of one temporary static method at the end of the class, and the static block deletes that method before any other static initializer runs. The method is keyed by a symbol created once at the top of the file. Field writes and their order are unchanged.Decorators kept for a later transform can still see the temporary method before it is deleted.
Transformer tests, clippy, formatting, and transform conformance passed. Both new fixtures and the exec fixture pass.
AI disclosure: prepared with AI assistance (models
group/smart-split[1m]and Claude Opus 5.5claude-opus-5-5; the reasoning effort level was not exposed).