feat(transformer): support lowering accessor with legacy decorators#20348
feat(transformer): support lowering accessor with legacy decorators#20348graphite-app[bot] merged 1 commit intomainfrom
accessor with legacy decorators#20348Conversation
ad82294 to
22c68b2
Compare
Merging this PR will not alter performance
Comparing Footnotes
|
fcf7f6b to
8ba153d
Compare
...onformance/tests/legacy-decorators/test/fixtures/oxc/accessor-with-class-properties/input.ts
Show resolved
Hide resolved
8ba153d to
c77e1c5
Compare
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. |
a9f3b9c to
df15346
Compare
tasks/transform_conformance/tests/legacy-decorators/test/fixtures/oxc/accessor/output.js
Outdated
Show resolved
Hide resolved
...onformance/tests/legacy-decorators/test/fixtures/oxc/accessor-with-class-properties/input.ts
Show resolved
Hide resolved
4c5ccb8 to
2f7fe91
Compare
tasks/transform_conformance/tests/legacy-decorators/test/fixtures/oxc/accessor/output.js
Show resolved
Hide resolved
tasks/transform_conformance/tests/legacy-decorators/test/fixtures/oxc/accessor/output.js
Show resolved
Hide resolved
|
I think it is good to go, merging now. Feel free to leave comments. I will follow up on it |
Merge activity
|
3b8bddd to
0d8aded
Compare
…#20348) ## Summary Closes #20133 - Lower decorated `accessor` properties to private backing field + getter/setter pair when `experimentalDecorators` is enabled, matching TypeScript's `classFields.ts` `transformAutoAccessor` - Only accessors with decorators are lowered — undecorated accessors are left as-is - Support computed accessor keys (e.g. `@dec accessor [expr]`) via temp var to ensure the key expression is evaluated only once - Accessor lowering runs in `enter_class` (Decorator plugin) so es2022 class-properties can further transform the generated private fields - Decorators are transferred from the accessor to the generated getter, so the legacy decorator transform emits `_decorate()` calls ### Transform example ```ts // Input class C { @dec accessor prop: string = "hello"; @dec accessor [expr]: any; } ``` ```js // Output (without class-properties) var _a = expr; class C { #_prop_accessor_storage = "hello"; get prop() { return this.#_prop_accessor_storage; } set prop(value) { this.#_prop_accessor_storage = value; } #_a; get [_a]() { return this.#_a; } set [_a](value) { this.#_a = value; } } babelHelpers.decorate([dec], C.prototype, "prop", null); babelHelpers.decorate([dec], C.prototype, _a, null); ``` ## Test plan - [x] New test `oxc/accessor` — decorated accessors without class-properties plugin (instance, static, initialized, computed key) - [x] New test `oxc/accessor-with-class-properties` — full pipeline with class-properties plugin (private fields transformed to WeakMap/brand patterns) - [x] New test `decoratorOnClassAccessorProperty1` — instance, static, and initialized accessor properties with decorators - [x] Existing `decoratorOnClassProperty13` output updated for accessor lowering - [x] Undecorated accessors are not lowered (`oxc-13284.js` coverage test passes) - [x] `cargo clippy`, `just fmt` clean 🤖 Generated with [Claude Code](https://claude.com/claude-code)
52e2c22 to
7215d9e
Compare
### 🚀 Features - 7215d9e transformer: Support lowering `accessor` with legacy decorators (#20348) (Dunqing) ### 🐛 Bug Fixes - 3bbd0cd transformer: Emit `Object` instead of `void 0` for untyped getter/setter `design:type` metadata (#20488) (Dunqing) - 4ae3f3f ecmascript: Apply coercion-is-pure assumption to constructor side-effect detection (#20420) (Dunqing) - 11f9695 transformer: Legacy decorator on computed property key leaves variable unassigned (#20430) (bab) - efeba28 ecmascript: Add argument validation for NewExpression side-effect detection (#20395) (Dunqing) Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>

Summary
Closes #20133
accessorproperties to private backing field + getter/setter pair whenexperimentalDecoratorsis enabled, matching TypeScript'sclassFields.tstransformAutoAccessor@dec accessor [expr]) via temp var to ensure the key expression is evaluated only onceenter_class(Decorator plugin) so es2022 class-properties can further transform the generated private fields_decorate()callsTransform example
Test plan
oxc/accessor— decorated accessors without class-properties plugin (instance, static, initialized, computed key)oxc/accessor-with-class-properties— full pipeline with class-properties plugin (private fields transformed to WeakMap/brand patterns)decoratorOnClassAccessorProperty1— instance, static, and initialized accessor properties with decoratorsdecoratorOnClassProperty13output updated for accessor loweringoxc-13284.jscoverage test passes)cargo clippy,just fmtclean🤖 Generated with Claude Code