Repository navigation
fix(transformer/typescript): don't evaluate keys of declare fields with removeClassFieldsWithoutInitializer - #30272
Merged
Conversation
…with `removeClassFieldsWithoutInitializer` With `removeClassFieldsWithoutInitializer`, the computed key of an undecorated `declare` field, such as `declare [f()]: any`, was moved into the class's computed key static block, so `f()` ran. A `declare` field is type-only: TypeScript and esbuild erase it with its key, as Oxc already does in the other field modes.
Dunqing
enabled auto-merge
November 25, 2026 16:22
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
|
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).
1 of 17 tasks
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
removeClassFieldsWithoutInitializer, the computed key of an undecorateddeclarefield, such asdeclare [f()]: any, was still evaluated: the TypeScript transform movedf()into the class's computed-key static block. Adeclarefield is type-only, so tsc and esbuild erase it together with its key, and Oxc's other field modes already do.Example
Input (playground for this example):
Options:
{ "assumptions": { "setPublicClassFields": true }, "plugins": [["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
node, the before output logs[ 'declared', 'field' ]and the after output logs[ 'field' ].Fix
The branch that keeps side-effecting keys of removed fields now skips
declarefields. Decorated fields take the branch above it, so legacy decorators still get their keys.A new fixture covers instance and static
declarefields with side-effecting keys, a plaindeclare x: number, and a non-declare[g()]: anywhose key is still evaluated, with an exec test of the evaluated keys; it fails before this change. Transformer tests, conformance with--exec, clippy, and transformer/semantic coverage pass with no snapshot changes beyond the new fixture.AI disclosure: written with Claude Code (Claude Opus 5.5; reasoning effort not recorded).