Repository navigation
Conversation
Contributor
Merging this PR will not alter performance
Comparing Footnotes
|
Dunqing
force-pushed
the
standard-decorators-members
branch
from
November 17, 2026 10:57
e066485 to
5bf3975
Compare
This was referenced Nov 17, 2026
Dunqing
force-pushed
the
standard-decorators-members
branch
from
November 19, 2026 03:28
5bf3975 to
0a14f00
Compare
Dunqing
force-pushed
the
standard-decorators-members
branch
from
November 19, 2026 11:52
0a14f00 to
d4d72b4
Compare
@dec on class members and classes (2/4)
Dunqing
force-pushed
the
standard-decorators-members
branch
from
November 19, 2026 17:48
d4d72b4 to
7f475dc
Compare
graphite-app Bot
pushed a commit
that referenced
this pull request
Nov 19, 2026
Standard decorator lowering needs helpers to apply decorators, share metadata, preserve class names, and run initializers. These helpers are not yet available in `@oxc-project/runtime` or the Test262 runtime harness.
Add `decorateElement`, `decoratorStart`, `decoratorKey`, `runInitializers`, `decoratorMetadata`, and `setClassName` as Oxc-owned helpers. Shared source generates their CommonJS, ESM, and coverage runtime copies. Babel runtime sync preserves these helpers and rejects upstream name collisions before writing.
`decoratorStart` can capture per-element public descriptors stored under temporary symbol keys on the original class. `decorateElement` accepts these explicit descriptors and can replay undecorated overrides without consuming initializer slots. This preserves each original method value, getter/setter pairing, method names, and home objects when public names collide. Existing callers keep the original protocol.
Metadata is installed as an own data property with Object.defineProperty, including when a class decorator returns a Proxy. This invokes the Proxy defineProperty trap and cannot be swallowed by an unrelated set trap.
### Example
Input:
```ts
const key = Symbol.metadata || Symbol.for("Symbol.metadata");
const events = [];
const replacement = new Proxy(class {}, {
set() { events.push("set"); return true; },
defineProperty(target, key, descriptor) { events.push("defineProperty"); return Reflect.defineProperty(target, key, descriptor); }
});
@(() => replacement)
class C {}
console.log(JSON.stringify({events, own: Object.hasOwn(C, key)}));
```
Before output:
```text
{"events":["set"],"own":false}
```
After output:
```text
{"events":["defineProperty"],"own":true}
```
Metadata must be an own data property even when the replacement Proxy swallows assignment.
These runtime results were captured from the original published decorator stack (`563f5dd5ff627c206b8910b00e7cf19bcde739f6`) and the corrected stack, using `proposal-decorators` version `2023-11`, with no target override. They show the correction folded into this layer; the full standard-decorator examples require the implementation layers above runtime helpers and the intermediate feature prerequisites. The playground does not expose the explicit standard-decorator lowering option used by these intermediate layers, so it cannot represent this configuration. Exact Babel options:
```json
{"plugins": [["proposal-decorators", {"version": "2023-11"}]]}
```
To reproduce the local transform, save the input as `example.ts`, save the matching Babel options as `example-options/options.json`, and run:
```bash
cargo run -p oxc_transformer --example transformer -- example.ts --babel-options ./example-options
```
Execute the emitted `Transformed` section in Node with `babelHelpers` resolving to this checkout’s `npm/runtime/src/helpers`.
Part of #9170.
## Review follow-up
Two commits added:
- `fix(runtime): keep source order of captured public class elements`. `decoratorStart` removed every captured public element and immediately redefined only the auto-accessors, so they moved ahead of other elements. For `class A { m() {} accessor x; @d [k]() {} }`, `Object.getOwnPropertyNames(A.prototype)` gave `constructor,x,m,n` instead of `constructor,m,x,n`. The first element of each name is now defined in source order, and decorated definitions replace it in place. As a result, a captured element is visible on the prototype while its decorators run, as non-captured decorated methods already were. The runtime test was updated for that. The order is also covered by the transformer exec fixture `oxc/public-element-order[--chrome94]` in #29750.
- `fix(runtime): ship esbuild's license notice with the standard decorator helpers`. The helpers are adapted from esbuild's runtime (MIT), but the package only shipped Babel's `LICENSE`, which `scripts/sync.mjs` overwrites on every sync. esbuild's notice is now shipped as `LICENSE-esbuild` and listed in `files` (checked with `npm pack --dry-run`), and a test keeps it there.
Checks at this layer: all 47 runtime/sync tests, `generate-decorator-helpers.mjs --check`, transformer tests, full transform conformance with execution. Conformance reports: Babel output 754/1190, Babel execution 342/592, Oxc output 337/462, Oxc execution 68/364.
Implemented with AI assistance.
Prepared with AI assistance (model ID: `mythos-magpie-4133180673`). The review follow-up was implemented with Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code; its reasoning effort level was not available to the agent.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_018ogydaCgdkgWgzV7R21DrC
Dunqing
force-pushed
the
standard-decorators-members
branch
from
November 20, 2026 00:09
6766f5f to
f7f43e6
Compare
Dunqing
force-pushed
the
standard-decorators-members
branch
from
November 23, 2026 06:40
090a767 to
aeeaf7e
Compare
Dunqing
force-pushed
the
standard-decorators-members
branch
from
November 24, 2026 01:03
aeeaf7e to
a8be1ca
Compare
Dunqing
force-pushed
the
standard-decorators-members
branch
from
November 24, 2026 19:27
e204e47 to
160007b
Compare
Dunqing
force-pushed
the
standard-decorators-members
branch
2 times, most recently
from
November 25, 2026 03:26
6d7f06f to
918fe9b
Compare
jwh3times
pushed a commit
to jwh3times/oxc
that referenced
this pull request
Nov 25, 2026
…xc-project#30204) A stack trace reports a call at its callee's position. When a transform emits a call whose callee it generated, such as a runtime helper reference, the callee has no span, so the call gets no source mapping of its own. A source-mapped stack trace through that call then points at whatever was mapped earlier, often the end of an enclosing block. This PR maps such a call at the call's own span, when the call has one. No transform on main gives a helper call a span yet. The standard decorator lowering in oxc-project#29750 is the first: it maps each `decorateElement`, `decoratorStart` and `decoratorMetadata` call to its decorators, so a throwing decorator's stack trace points at that decorator. ### Example Input: `foo();\nbar(1);`, parsed and then given a generated callee by clearing the span of `bar`, as the new `call_with_generated_callee_maps_to_call_span` test does. There is no playground link: the playground can't produce a callee without a span, because that needs a transform that only exists in the decorator stack, or an AST edit. Before output (`origin/main`), the code and the source map tokens of line 2: ```text foo(); bar(1); generated 2:4 -> source 2:4 generated 2:5 -> source 2:5 ``` After output: ```text foo(); bar(1); generated 2:0 -> source 2:0 generated 2:4 -> source 2:4 generated 2:5 -> source 2:5 ``` The call on line 2 gains a mapping at its start, where a stack trace through it reports its position. Before, the first mapping on that line was the argument list. [Source map viewer: main (A) versus this PR (B)](https://source-map-viewer.void.app/compare?a=eJxNjjELwjAQhf-KnEuF0CJuKQ5HpoougpPnEO0pLfQSktal9L9Lbalu97jvPb4eXiwcbMulcSWDhqdzySYnuduQbMeDJMvWq-i68OCT9b6S1-V83C-9tI5pYz0JKFioQ3QCGnqCN4dYOSHQO0UgtuFIoK83RTP9jQSV-K5N60jw9zJOWpZ2ImaznxrJBDeT1ThEgIioCsQiL9CgMoiGYIDhA7YdTcU&b=eJxNjj0LwjAQhv-KnEuF0CJuKQ5HphZdBCfPIdooLfQSktSl9L9LP6hu7_E-9_L08DZsvI6mUrYyIOFlbbLLiR_aJ_sxEGfZdhNs55_mrJ2r-X29nI7rX9qEtNWOGASsVBksg4Se4GN8qC0TyIMgYN2aQCBvd0ELPZ0ENbsupk0g-KuU5Wg4zsRi9lMjnuF2thqHCBARRYFY5IiqnJJQiIpggOELPRRPBg&tab=table&ignore-source-name=0) Calls whose callee comes from the source are unchanged, and so are generated calls without a span: `add_source_mapping` skips empty spans. The new test fails without the change. `oxc_codegen`, `oxc_transformer`, `oxc_transformer_plugins`, `oxc_minifier` and `oxc` tests pass. AI disclosure: written with Claude Code (Claude Opus 5.5; reasoning effort not recorded).
Dunqing
force-pushed
the
standard-decorators-members
branch
from
November 25, 2026 04:01
918fe9b to
9b7c80c
Compare
Dunqing
force-pushed
the
standard-decorators-members
branch
2 times, most recently
from
November 25, 2026 07:01
ba39387 to
5366b0f
Compare
Dunqing
marked this pull request as ready for review
November 25, 2026 08:56
Dunqing
force-pushed
the
standard-decorators-members
branch
2 times, most recently
from
November 25, 2026 10:58
5c41a52 to
67a72d3
Compare
Dunqing
added a commit
to rolldown/rolldown
that referenced
this pull request
Nov 25, 2026
Patches every oxc crate to oxc-project/oxc@9e2856b2, the head of the stack that adds standard decorator and auto-accessor lowering (oxc-project/oxc#29749, oxc-project/oxc#29750, oxc-project/oxc#29751, oxc-project/oxc#28882). Drop the patch once an oxc release includes it. The stack sits on a newer oxc main, whose changes update some snapshots: - Legacy decorators: computed and assigned keys are passed to __decorate instead of null, and decorated static fields keep their decorators. - Source maps: calls whose callee is generated, such as a wrapped require(), init_*() or (0, x.f)(), map to their own source call instead of a neighbouring token (oxc-project/oxc#30204).
1 of 17 tasks
Dunqing
force-pushed
the
standard-decorators-members
branch
from
November 25, 2026 17:23
4e49fa7 to
e6d179f
Compare
Dunqing
force-pushed
the
standard-decorators-members
branch
2 times, most recently
from
November 26, 2026 02:03
15b7ae9 to
059e426
Compare
Dunqing
force-pushed
the
standard-decorators-members
branch
2 times, most recently
from
November 26, 2026 02:41
df47aac to
7e5b774
Compare
Dunqing
force-pushed
the
standard-decorators-members
branch
3 times, most recently
from
November 26, 2026 05:08
eee650c to
271a8a1
Compare
Lower TC39 2023-11 decorators on methods, getters, setters, fields, auto-accessors and classes, with decorator context objects, `addInitializer`, `Symbol.metadata` and the spec's evaluation order. A decorated class is lowered as a whole, and runtime helpers from `@oxc-project/runtime` apply the decorators after the class. Document on the External helper mode that lowered decorators call helpers Babel's `babelHelpers` does not provide.
Dunqing
force-pushed
the
standard-decorators-members
branch
from
November 26, 2026 09:02
271a8a1 to
8665662
Compare
This branch has not been deployed
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.
Stack 2/4 for standard (TC39 2023-11) decorators, and the main implementation. This PR lowers
@decon class members and on the class itself, with decorator context objects,addInitializer,Symbol.metadata, and the spec's order for decorators, keys, initializers and extra initializers. A decorated class is lowered whole, as in esbuild, because decorators can observe and replace its elements.Class replacement, decorator
thisreceivers and parameter decorators come in #29751; lowering is opt-in withdecorator: { lower: true }until #28882.Example
Input:
Output with
decorator: { lower: true }at es2022, in external helper mode (runtime mode imports the same helpers from@oxc-project/runtime, added in #29447):Decorator expressions are evaluated into
_x_decarrays before the class; after it, the runtime helpers apply the decorators in spec order. No playground link: the released playground doesn't lower standard decorators.Points to review
Start at
es2022/class_properties/decorators.rs. The runtime protocol (context array slots and flags) is documented indecorator/standard/mod.rsandnpm/runtime/scripts/helpers/. Cases that are easy to get wrong, each covered by fixtures:{ x: @dec class {} as any }givesname === "x", as dosatisfies,!and<T>.decorateElementcall maps to its decorated element in source maps, so a stack trace from a throwing decorator points at that decorator (codegen support from fix(codegen): map a call with a generated callee at the call's span #30204).[Symbol.iterator]can't collide with a string name and keeps every key; the temporary keys keep their original key's source position.The External helper mode's docs (Rust and napi, including
Helpers.mode) now warn that lowered decorators call helpers Babel doesn't define, such asdecoratorStartand the legacydecorateParam, so theRuntimemode is needed when decorators are lowered.Transformer tests, clippy and transform conformance with execution pass. Compared with #29749: Babel output 759 → 766/1208, Babel execution 350 → 496/602, Oxc output 375 → 378/498, Oxc execution 90 → 421/429. Of the 19 remaining Babel decorator execution failures, 13 test class replacement and 4 test decorator
thisor the outer class binding, both handled in #29751, which explains the ones that still fail there. The twoduplicated-keys--to-es2015fixtures expect Babel's 'Decorating two elements with the same name' error, which the spec doesn't require.Depends on #29749. 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).