Skip to content

feat(transformer/decorators)!: lower decorators by default when a target is set (4/4) - #28882

Open
Dunqing wants to merge 1 commit into
standard-decorators-evaluationfrom
decorators-lowering
Open

Dunqing wants to merge 1 commit into
standard-decorators-evaluationfrom
decorators-lowering

Conversation

@Dunqing

@Dunqing Dunqing commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Stack 4/4 for standard (TC39 2023-11) decorators. This PR lowers no new syntax; it decides when the lowering from #29749, #29750 and #29751 runs. That is now by default at any concrete target, instead of only with decorator: { lower: true }.

Options Before After
target: "es2022" (or engine versions), no decorator option @dec and accessor kept lowered
No target, or esnext kept kept
decorator: { lower: false } kept kept, at any target
decorator: { legacy: true } legacy lowering legacy lowering (takes precedence)

Breaking change: with a concrete target (an ES edition, engine versions, or a mix), standard decorators and auto-accessors are now lowered by default. In Runtime helper mode, the output imports decoratorStart, decorateElement, runInitializers, decoratorMetadata, decoratorKey and setClassName from @oxc-project/runtime (added in #29447).

This also adds DecoratorOptions::transforms_decorators(env, scoping): callers that skip the transformer when EnvOptions::lowers_syntax() (#30251) is false can ask whether a program still needs it for decorators or accessor properties, from the same decision Transformer::build_with_scoping uses.

Cost

With the new default, every concrete target would run class-properties on every class, statement and expression. SemanticBuilder, which visits every node anyway, now records whether the program has a decorator or an accessor property; without one, the transformer builds the same transforms as before. @ in comments, strings or CSS templates and accessor as an identifier don't count.

Transform-only instruction counts (callgrind) for files without decorators, compared with main:

File es2015 es2021 es2022
react.development.js +2.95% +3.83% −0.58%
react-dom-client.development.js +2.84% +3.71% −1.06%
TypeScript checker.ts +2.29% +2.83% −0.64%
TypeScript binder.ts +2.30% +2.81% −0.53%
excalidraw App.tsx +2.03% +2.92% −0.42%

Below es2022, where main already runs class-properties, the cost comes from #29749, #29750 and #29751; this PR itself is 0.1% to 0.5% cheaper than #29751 at every target. A file with at least one decorator or accessor takes the full path, so class-properties' hooks run on every node of that file. With one class appended that has a decorated method and a decorated accessor, es2022 costs +9.4% (App.tsx), +6.6% (checker.ts) and +18.6% (react.development.js) compared with main, which leaves that syntax in place. cargo allocs snapshots are unchanged.

Transformer and semantic tests, transform conformance with execution, napi tests and full coverage pass. Compared with #29751, conformance differs only in Oxc execution, 453 → 457/459, from this PR's fixtures. The Test262 runtime suite passes 17453/18403 against main's 17430: 22 decorator and accessor syntax tests now pass, and the remaining difference is a timeout flake in main's snapshot.

Follow-ups that don't block the stack are tracked in #30265.

Depends on #29751. Part of #9170.

AI disclosure: implemented and described with AI assistance; this revision was written with Claude Code (Claude Opus 5.5; reasoning effort not recorded).

@github-actions github-actions Bot added the A-transformer Area - JS/TS transforms and downleveling, oxc_transformer label Nov 6, 2026
@codspeed

codspeed Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

Warning

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.

✅ 91 untouched benchmarks
⏩ 19 skipped benchmarks1


Comparing decorators-lowering (2566b98) with standard-decorators-evaluation (e79783e)2

Open in CodSpeed

Footnotes

  1. 19 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on standard-decorators-evaluation (cade07b) during the generation of this report, so f7782dc was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@Dunqing
Dunqing force-pushed the decorators-lowering branch from 5ade138 to b61c5a0 Compare November 6, 2026 07:47
@Dunqing
Dunqing force-pushed the decorators-lowering branch 2 times, most recently from b0e34e4 to 2023d40 Compare November 11, 2026 00:44
@Dunqing
Dunqing force-pushed the decorators-lowering branch 7 times, most recently from 5107a9b to 9514c86 Compare November 12, 2026 02:28
@Dunqing
Dunqing force-pushed the decorators-lowering branch from 7c98aec to 83f5e02 Compare November 12, 2026 17:05
@Dunqing
Dunqing changed the base branch from decorators-test-infra to graphite-base/28882 November 13, 2026 16:36
@Dunqing
Dunqing force-pushed the decorators-lowering branch from f42988c to c5ed32c Compare November 13, 2026 16:38
@Dunqing
Dunqing changed the base branch from graphite-base/28882 to decorators-test-infra November 13, 2026 16:38
@Dunqing
Dunqing force-pushed the decorators-lowering branch from a2282f8 to 14ac79b Compare November 19, 2026 03:28
@github-actions github-actions Bot added the A-napi Area - Node.js bindings and WASM builds of the napi/ packages, oxc_napi label Nov 19, 2026
@Dunqing
Dunqing force-pushed the decorators-lowering branch 2 times, most recently from 979e186 to ce150dc Compare November 19, 2026 15:55
@Dunqing
Dunqing force-pushed the decorators-lowering branch from ce150dc to 729cf68 Compare November 19, 2026 16:00
@Dunqing Dunqing changed the title feat(transformer)!: lower standard decorators by default at concrete targets feat(transformer)!: lower standard decorators and auto-accessors by default at concrete targets Nov 19, 2026
@Dunqing Dunqing changed the title feat(transformer)!: lower standard decorators and auto-accessors by default at concrete targets feat(transformer/decorators)!: lower decorators by default when a target is set (4/4) Nov 19, 2026
@Dunqing
Dunqing force-pushed the decorators-lowering branch 2 times, most recently from d631584 to cbcdc72 Compare November 20, 2026 00:09
@Dunqing
Dunqing force-pushed the decorators-lowering branch from cbcdc72 to c7d11b3 Compare November 20, 2026 08:28
@Dunqing
Dunqing force-pushed the decorators-lowering branch from c7d11b3 to d57e2df Compare November 23, 2026 06:40
@Dunqing
Dunqing added this pull request to stack #30053 November 23, 2026 06:40
@Dunqing
Dunqing force-pushed the decorators-lowering branch 2 times, most recently from 889244c to 66ef37a Compare November 24, 2026 01:03
…get is set

Lower standard decorators and auto-accessors by default at any concrete
target; `decorator: { lower: false }` keeps them. Programs without
decorators or `accessor` skip the work, using a flag recorded by
`oxc_semantic`. Add `DecoratorOptions::transforms_decorators` so callers
can tell whether a program needs decorator lowering.

BREAKING CHANGE: with a concrete target, standard decorators and
auto-accessors are now lowered by default.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-napi Area - Node.js bindings and WASM builds of the napi/ packages, oxc_napi A-semantic Area - Scopes, symbols, references and semantic errors, oxc_semantic A-transformer Area - JS/TS transforms and downleveling, oxc_transformer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant