Skip to content

fix(transformer): map lowered auto-accessors and class field initializers to their source - #30326

Merged
Dunqing merged 1 commit into
mainfrom
accessor-lowering-source-positions
Nov 26, 2026
Merged

Dunqing merged 1 commit into
mainfrom
accessor-lowering-source-positions

Conversation

@Dunqing

@Dunqing Dunqing commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

The storage field, getter and setter that lowering generates for an accessor field have no source positions. Stepping into the getter or setter in a debugger shows no original location, and the _defineProperty(...) / _classPrivateFieldInitSpec(...) calls that class-properties emits for field initializers map only their arguments.

Example

Input (playground for this example):

class C {
  @dec accessor x = 1;
}
class D {
  y = 1;
  static z = 2;
}

Options: target: "es2021", legacy decorators, source map on. Each line lists its decoded mappings as generated→line:column original.

Before output:

_classPrivateFieldInitSpec(this, _x_accessor_storage, 1);  // `1`→2:20 `1`
get x() {                                                  // `x`→2:16 `x`
  return _classPrivateFieldGet(_x_accessor_storage, this); // (none)
set x(value) {                                             // (none)
  _classPrivateFieldSet(_x_accessor_storage, this, value); // (none)
_defineProperty(this, "y", 1);                             // `"`→5:2 `y`, `1`→5:6 `1`
_defineProperty(D, "z", 2);                                // `"`→6:9 `z`, `2`→6:13 `2`

After output:

_classPrivateFieldInitSpec(this, _x_accessor_storage, 1);  // `_classPrivateFieldInitSpec`→2:2 `@dec`, `1`→2:20 `1`, `)`→2:21 `;`
get x() {                                                  // `get`→2:2 `@dec`, `x`→2:16 `x`, `{`→2:2 `@dec`
  return _classPrivateFieldGet(_x_accessor_storage, this); // `return`→2:16 `x`
set x(value) {                                             // `set`→2:2 `@dec`, `x`→2:16 `x`, `{`→2:2 `@dec`
  _classPrivateFieldSet(_x_accessor_storage, this, value); // `_classPrivateFieldSet`→2:16 `x`
_defineProperty(this, "y", 1);                             // `_defineProperty`→5:2 `y`, `1`→5:6 `1`, `)`→5:7 `;`
_defineProperty(D, "z", 2);                                // `_defineProperty`→6:2 `static`, `"`→6:9 `z`, `2`→6:13 `2`, `)`→6:14 `;`

Before and after in the source map viewer

The storage, getter, setter and their bodies now take the accessor's span, which starts at its first decorator like other class elements. The statements in the bodies map to the accessor's key instead: a source map drops a mapping whose original position repeats the previous one, so giving them the accessor's span would leave those lines unmapped. On main only legacy decorators use this builder; the standard-decorator stack (#29749) reuses it and gets the same mappings once rebased. The field initializer calls map to their fields, as the assignments in loose mode already did.

var _x = new WeakMap() declarations for lowered private fields remain unmapped; that is unchanged here.

Transformer tests, transform conformance (--exec, no snapshot changes) and the oxc-transform napi tests pass. The new source_map integration tests fail without the change.

AI disclosure: written with Claude Code (Claude Opus 5.5; reasoning effort not recorded).

…zers to their source

The storage field, getter and setter generated for an `accessor` field
had no source positions, so stepping into them in a debugger showed no
original location. They now map to the accessor, and the statements in
the getter and setter bodies map to its key.

`_defineProperty(...)` and `_classPrivateFieldInitSpec(...)` calls that
class-properties emits for field initializers now map to their fields,
as the assignments in loose mode already did.
@github-actions github-actions Bot added the A-transformer Area - JS/TS transforms and downleveling, oxc_transformer label Nov 26, 2026
@codspeed

codspeed Bot commented Nov 26, 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.

✅ 81 untouched benchmarks
⏩ 29 skipped benchmarks1


Comparing accessor-lowering-source-positions (051b29c) with main (ca243ee)2

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

  2. No successful run was found on main (58b07b7) during the generation of this report, so ca243ee was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@Dunqing

Dunqing commented Nov 26, 2026 •

Copy link
Copy Markdown
Member Author

I can see this is a nice improvement from Before and after in the source map viewer

@Dunqing
Dunqing added this pull request to the merge queue Nov 26, 2026
Merged via the queue into main with commit ab59476 Nov 26, 2026
42 checks passed
@Dunqing
Dunqing deleted the accessor-lowering-source-positions branch November 26, 2026 08:16
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