Repository navigation
fix(transformer): map lowered auto-accessors and class field initializers to their source - #30326
Conversation
…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.
Merging this PR will not alter performanceWarning 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.
Comparing Footnotes
|
|
I can see this is a nice improvement from Before and after in the source map viewer |
The storage field, getter and setter that lowering generates for an
accessorfield 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):
Options:
target: "es2021", legacy decorators, source map on. Each line lists its decoded mappings asgenerated→line:column original.Before output:
After output:
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 theoxc-transformnapi tests pass. The newsource_mapintegration tests fail without the change.AI disclosure: written with Claude Code (Claude Opus 5.5; reasoning effort not recorded).