Repository navigation
fix(transformer/legacy-decorator): evaluate computed keys of decorated declare fields - #30264
Merged
Merged
Conversation
Contributor
Merging this PR will not alter performanceWarning oxc-project has exceeded the Hobby plan limit of 5 active contributors. Upgrade your plan or apply to the open source program by December 8, 2026 to keep using CodSpeed.
Comparing Footnotes
|
1 of 17 tasks
Dunqing
force-pushed
the
fix/legacy-decorator-declare-computed-key
branch
4 times, most recently
from
November 26, 2026 01:04
114c81b to
b525e65
Compare
…d `declare` fields A legacy-decorated `declare` field whose computed key has side effects, such as `@dec declare [key()]: any`, got an unassigned temp var as its decorator key, and `key()` was never called: TypeScript removes the field along with the `_key = key()` assignment that legacy decorators put in its key. An identifier key, `@dec declare [k]: any`, also got an unassigned temp var, and its import was removed as type-only. TypeScript now replaces such a key with a temp var, assigned in order with the other class keys (in the next computed key the class evaluates, or a static block), and marks the key's references as reads. Legacy decorators pass identifier and literal keys of `declare` fields to `_decorate` as is. This only applies with legacy decorators. Without them, TypeScript keeps erasing decorated `declare` fields with their decorators and keys, as tsc does (it reports TS1206 for such decorators).
Dunqing
force-pushed
the
fix/legacy-decorator-declare-computed-key
branch
from
November 26, 2026 01:20
b525e65 to
9ccd228
Compare
Dunqing
added a commit
to rolldown/rolldown
that referenced
this pull request
Nov 26, 2026
Pins the decorators-lowering head restacked onto oxc main 746ad93f. Snapshot changes from oxc main: - ts_experimental_decorators: computed keys of decorated `declare` fields are evaluated and passed to __decorate again (oxc-project/oxc#30264). - ts_declare_class_fields: keys of `declare` fields are no longer evaluated, as tsc and esbuild do (oxc-project/oxc#30272). - invalid_define_config/value: the error names the key and value (oxc-project/oxc#30280).
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.
With legacy decorators (
experimentalDecorators), a decorateddeclarefield whose computed key has side effects, such as@dec declare [key()]: any, gotundefinedas its decorator key, andkey()never ran: legacy decorators put_key = key()in the field's key, but TypeScript removesdeclarefields with their keys. Define mode was already broken; #29979 brokeuseDefineForClassFields: false, which used to callkey()(with anullkey). An identifier key,@dec declare [k]: any, also got an unassigned temp var, and an importedkwas removed as type-only.Example
Input (playground for this example):
Options:
{ "assumptions": { "setPublicClassFields": true }, "plugins": ["transform-legacy-decorator", ["transform-typescript", { "removeClassFieldsWithoutInitializer": true }]] }Command:
cargo run -p oxc_transformer --example transformer -- input.ts --babel-options <dir with options.json>Before output:
After output:
Run with a minimal
babelHelpers.decorate, the before output logs[ 'dec:undefined' ]and the after output logs[ 'key', 'dec:k' ]. tsc passeskey()to__decoratedirectly; esbuild evaluates it in order with the other class keys, which this follows.Fix
The TypeScript transform now replaces such a key with a temp var whose assignment joins the class's other computed keys, in source order: it is prepended to the next key the class evaluates, or put in a static block when none follows. This covers define and assign semantics and class-properties lowering. It also marks the key's references, which semantic resolves as types in a
declarefield, as reads. Legacy decorators then pass identifier and literal keys ofdeclarefields to_decorateas is. Other decorator modes are unchanged: TypeScript still erases decorateddeclarefields together with their decorators, as tsc does (it reports TS1206 for them).New fixtures cover instance and static fields in all three field modes, with an exec test of the evaluation order, and that keys stay unevaluated without legacy decorators; the legacy ones fail before this change. Transformer tests, conformance with
--exec, clippy, and transformer/semantic coverage pass. The one coverage change,decoratorInAmbientContext.ts, now passesbinstead of an unassigned_b, as tsc's baseline does.AI disclosure: written with Claude Code (Claude Opus 5.5; reasoning effort not recorded).