Skip to content

fix(transformer/typescript): hide computed key methods from decorators - #30184

Merged
Dunqing merged 1 commit into
fix/typescript-computed-key-static-blockfrom
fix/typescript-decorator-computed-key-visibility
Nov 24, 2026
Merged

Dunqing merged 1 commit into
fix/typescript-computed-key-static-blockfrom
fix/typescript-decorator-computed-key-visibility

Conversation

@Dunqing

@Dunqing Dunqing commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

A standard element decorator can inspect the class before its static blocks run. With setPublicClassFields enabled, it can see the symbol-keyed method that #30148 generates to evaluate a computed key. The source class has no such property.

Example

const observed = [];
function inspect(getClass) {
  observed.push(Object.getOwnPropertySymbols(getClass()).filter(key => key !== Symbol.metadata));
}
function* make() {
  return class C {
    @inspect static getClass() { return C; }
    static [yield "key"] = 1;
  };
}
const it = make();
expect(it.next().value).toBe("key");
const C = it.next("x").value;
expect(C.x).toBe(1);
expect(observed).toEqual([[]]);

The Oxc playground cannot run the downstream decorator pass that exposes the extra symbol. To print the JavaScript locally, save the input as /tmp/repro.ts and run the transformer example with the fixture options.

fixture=tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/oxc/preserved-class-context-dependent-computed-keys
cargo run -p oxc_transformer --example transformer -- /tmp/repro.ts --babel-options "$fixture/options.json"

Before, the generated method and cleanup were visible in the output.

static {
  delete this[_computedKey];
}
// …
static [(_yield$key = yield "key", _computedKey)]() {}

After, the key runs in a decorator expression on a private method.

@(_yield$key = yield "key", () => {}) static #_computedKey() {}

The generator still yields "key", and the static field receives 1. With Babel 2023-11 and esbuild, the inspecting decorator saw one extra symbol before and zero after. The runtime fixture also exercises a user-defined symbol and enclosing private names accessed directly and through eval.

cargo run -p oxc_transform_conformance -- --filter /downstream-decorators/ --exec

The focused runtime result is Passed: 1 of 1. Transformer tests and lint passed. Transformer coverage snapshots matched, and full transform conformance recorded one additional passing Oxc exec fixture.

AI disclosure: prepared with AI assistance. The exact model version and reasoning effort were not recorded.

@Dunqing
Dunqing added this pull request to stack #30185 November 24, 2026 16:08
@github-actions github-actions Bot added the A-transformer Area - JS/TS transforms and downleveling, oxc_transformer label Nov 24, 2026
@codspeed

codspeed Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 81 untouched benchmarks
⏩ 29 skipped benchmarks1


Comparing fix/typescript-decorator-computed-key-visibility (57fc7aa) with fix/typescript-computed-key-static-block (a81c69d)

Open in CodSpeed

Footnotes

  1. 29 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. ↩

@Dunqing
Dunqing marked this pull request as ready for review November 24, 2026 16:29
@Dunqing Dunqing added the run-monitor-oxc Add to a PR to dispatch oxc-project/monitor-oxc CI against it label Nov 24, 2026
@oxc-guard

oxc-guard Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

@oxc-guard oxc-guard Bot removed the run-monitor-oxc Add to a PR to dispatch oxc-project/monitor-oxc CI against it label Nov 24, 2026
@Dunqing
Dunqing added this pull request to the merge queue Nov 24, 2026
Merged via the queue into main with commit 1abb96d Nov 24, 2026
40 of 41 checks passed
@Dunqing
Dunqing deleted the fix/typescript-decorator-computed-key-visibility branch November 24, 2026 16:48
Dunqing added a commit to rolldown/rolldown that referenced this pull request Nov 24, 2026
Pins the restacked decorators-lowering head, now on oxc main 1abb96db.

Snapshot changes:
- Legacy decorator fixtures pick up main's fixes: computed and assigned
  keys are passed to __decorate instead of null, and decorated static
  fields keep their decorators (oxc-project/oxc#29979, oxc-project/oxc#30148,
  oxc-project/oxc#30184).
- Generated calls whose callee has no source position now map to the
  call itself, so wrapped require(), init_*() and (0, x.f)() calls point
  at their source call rather than a neighbouring token.
- _decoratorStart and _decorateElement now map to the class and to each
  decorated element, so a throwing decorator's frame lands on it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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