fix(transformer/legacy-decorator): static class fields cannot be accessed in static field initializer when class-properties plugin is not enabled#11143
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
CodSpeed Instrumentation Performance ReportMerging #11143 will not alter performanceComparing Summary
|
404cdd4 to
38387b7
Compare
There was a problem hiding this comment.
Pull Request Overview
Adds missing legacy-decorator logic for static class field initializers when the transform-class-properties plugin is not enabled, matching TypeScript’s behavior.
- Tracks whether class-properties plugin is enabled in the transform context
- Updates the TypeScript transformer to use the new context flag instead of a constructor parameter
- Injects a static block alias assignment (
_Class = this) before evaluating static fields when needed - Adds/updates conformance tests and snapshots for both “static-field” and “static-field-with-class-properties” cases
Reviewed Changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tasks/transform_conformance/tests/legacy-decorators/static-field/input.ts | New test input for decorator + static-field scenario |
| tasks/transform_conformance/tests/legacy-decorators/static-field/output.js | Expected transformed output including static block alias logic |
| tasks/transform_conformance/tests/legacy-decorators/static-field/options.json | Plugin config for legacy-decorator only |
| tasks/transform_conformance/tests/legacy-decorators/static-field/exec.ts | Execution test case |
| tasks/transform_conformance/tests/legacy-decorators/static-field-with-class-properties/* | Same as above but with transform-class-properties enabled |
| tasks/transform_conformance/snapshots/oxc_exec.snap.md | Updated pass counts for new tests |
| tasks/transform_conformance/snapshots/oxc.snap.md | Updated legacy-decorators test counts and symbol mismatches |
| crates/oxc_transformer/src/context.rs | Added is_class_properties_plugin_enabled flag in context |
| crates/oxc_transformer/src/lib.rs | Simplified TypeScript::new call by removing plugin arg |
| crates/oxc_transformer/src/typescript/mod.rs | Removed old flag field; switched to context-based check |
| crates/oxc_transformer/src/decorator/legacy/mod.rs | Ported TS logic to insert _Class = this static block |
Comments suppressed due to low confidence (1)
crates/oxc_transformer/src/context.rs:50
- [nitpick] The field
is_class_properties_plugin_enabledconflates environment support and plugin presence. Consider renaming it (e.g.,class_properties_env_supportedorclass_properties_plugin_enabled) to clearly communicate whether it reflects target-level support or actual plugin activation.
pub is_class_properties_plugin_enabled: bool,
Merge activity
|
…ssed in static field initializer when `class-properties` plugin is not enabled (#11143) close: #11111 This is the missing part we were ported from [TypeScript](https://github.com/microsoft/TypeScript/blob/b86ab7dbe0eb2f1c9a624486d72590d638495c97/src/compiler/transformers/legacyDecorators.ts#L345-L366).
38387b7 to
468ddf4
Compare

close: #11111
This is the missing part we were ported from TypeScript.