fix(transformer): propagate source spans for sourcemap correctness#19258
fix(transformer): propagate source spans for sourcemap correctness#19258graphite-app[bot] merged 1 commit intomainfrom
Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
Merge activity
|
…19258) ## Summary - Propagate original source node spans to their outermost transformed replacements across all transformer plugins - Codegen skips sourcemap entries for nodes with empty spans (`SPAN`), so transformed nodes previously produced no sourcemap mappings - Updated 20 files across typescript, jsx, es2016-es2026, class properties, and shared utility functions - Added `span: Span` parameters to shared helpers (`create_assignment`, `create_member_callee`, `create_prototype_member`) and threaded spans through call chains - Kept `SPAN` for truly synthetic nodes (generated temps, helper function internals, protocol boilerplate) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
941bc03 to
5bdaacc
Compare
There was a problem hiding this comment.
Pull request overview
This PR improves sourcemap correctness by propagating original source spans onto transformed AST nodes (instead of leaving SPAN), so codegen emits mappings for transformed output across multiple transformer passes.
Changes:
- Thread
Spanthrough shared AST builder helpers (e.g. member callee/prototype member/assignment) and update call sites. - Update several transformers (TypeScript namespace/enum, JSX refresh/runtime, optional chaining, object rest/spread, async transforms, etc.) to stamp transformed nodes with the originating span.
- Preserve
SPANfor intentionally synthetic nodes while ensuring outermost replacements carry real spans.
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| crates/oxc_transformer/src/utils/ast_builder.rs | Adds span plumbing to shared AST construction helpers so callers can preserve source mappings. |
| crates/oxc_transformer/src/typescript/namespace.rs | Uses namespace node spans for generated declarations/exports and function wrappers. |
| crates/oxc_transformer/src/typescript/enum.rs | Propagates enum/enum-member spans into generated IIFE/calls/assignments. |
| crates/oxc_transformer/src/jsx/refresh.rs | Uses original expression/function spans for inserted refresh calls/statements. |
| crates/oxc_transformer/src/jsx/jsx_impl.rs | Uses JSX element span for generated props object/children array nodes. |
| crates/oxc_transformer/src/es2026/explicit_resource_management.rs | Threads statement spans into generated try/catch/finally scaffolding. |
| crates/oxc_transformer/src/es2022/class_properties/super_converter.rs | Updates helper calls to match new span-threaded builder signatures. |
| crates/oxc_transformer/src/es2022/class_properties/prop_decl.rs | Propagates PropertyDefinition spans into generated helper calls/assignments. |
| crates/oxc_transformer/src/es2022/class_properties/private_field.rs | Updates helper calls to match new span-threaded builder signatures. |
| crates/oxc_transformer/src/es2022/class_properties/constructor.rs | Updates helper calls to match new span-threaded builder signatures. |
| crates/oxc_transformer/src/es2022/class_properties/class.rs | Updates helper calls to match new span-threaded builder signatures. |
| crates/oxc_transformer/src/es2021/logical_assignment_operators.rs | Uses original assignment span for the rewritten logical expression node. |
| crates/oxc_transformer/src/es2020/optional_chaining.rs | Uses original chain-expression span for the rewritten conditional expression node. |
| crates/oxc_transformer/src/es2018/object_rest_spread.rs | Ensures the final rewritten call expression retains the original object expression span. |
| crates/oxc_transformer/src/es2018/async_generator_functions/for_await.rs | Propagates for await statement span through generated for/try scaffolding. |
| crates/oxc_transformer/src/es2017/async_to_generator.rs | Uses original await/arrow/function spans for rewritten yield/IIFE call nodes. |
| crates/oxc_transformer/src/es2016/exponentiation_operator.rs | Propagates original expression span through rewritten Math.pow/sequence nodes. |
| crates/oxc_transformer/src/decorator/legacy/mod.rs | Updates helper calls to match new span-threaded builder signatures. |
| crates/oxc_transformer/src/common/computed_key.rs | Updates computed-key temp-var assignment generation to use new span-threaded builder signature. |
| crates/oxc_transformer/src/common/arrow_function_converter.rs | Uses original spans for newly generated call expressions in super transforms. |
| ctx.state.var_declarations.insert_let(&binding, None, ctx.ast); | ||
|
|
||
| let assignment = create_assignment(&binding, key, ctx); | ||
| let assignment = create_assignment(&binding, key, SPAN, ctx); | ||
| let ident = binding.create_read_expression(ctx); |
There was a problem hiding this comment.
create_computed_key_temp_var passes SPAN into create_assignment, so the generated _tmp = <key> assignment will have an empty span and be skipped by sourcemap generation. Since this assignment corresponds to evaluating the original computed key expression, capture the original key span before moving it and pass that span instead.
### 🚀 Features - 429d876 semantic: Assign ast node ids during semantic build (#19263) (Boshen) - ebb80b3 ast: Add `node_id` field to all AST struct nodes (#18138) (Boshen) ### 🐛 Bug Fixes - bfb15a3 semantic: Make multi_index_vec clone panic-safe (#19299) (Boshen) - 41c50a5 transformer: Ignore invalid JSX pragma identifiers (#19296) (Boshen) - deed3d8 transformer: Remove unnecessary trailing expression in object rest spread assignment (#19259) (Boshen) - 5bdaacc transformer: Propagate source spans for sourcemap correctness (#19258) (Boshen) - 3e0e5ba isolated-declarations: Align readonly class array initializer diagnostics with tsc (#19218) (camc314) ### ⚡ Performance - c169c77 syntax: Optimize `is_identifier_name_patched` (#19386) (sapphi-red) - aa1e1a8 allocator: Inline BitSet accessors (#19331) (Boshen) - 5b90d46 semantic: Improve SoA with multi index vec (#19138) (Boshen) - 99ce2a6 isolated_declarations: Mark all diagnostic functions as `#[cold]` (#19279) (camc314) - dd0220f transformer: Remove TS-only nodes earlier in `enter_statements` (#19166) (Dunqing) - e5baf60 isolated-declarations: Replace hash collections with index-based Vec (#19221) (Dunqing) ### 📚 Documentation - 569aa61 rust: Add missing rustdocs and remove missing_docs lint attrs (#19306) (Boshen)
…xc-project#19258) ## Summary - Propagate original source node spans to their outermost transformed replacements across all transformer plugins - Codegen skips sourcemap entries for nodes with empty spans (`SPAN`), so transformed nodes previously produced no sourcemap mappings - Updated 20 files across typescript, jsx, es2016-es2026, class properties, and shared utility functions - Added `span: Span` parameters to shared helpers (`create_assignment`, `create_member_callee`, `create_prototype_member`) and threaded spans through call chains - Kept `SPAN` for truly synthetic nodes (generated temps, helper function internals, protocol boilerplate) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
### 🚀 Features - 429d876 semantic: Assign ast node ids during semantic build (oxc-project#19263) (Boshen) - ebb80b3 ast: Add `node_id` field to all AST struct nodes (oxc-project#18138) (Boshen) ### 🐛 Bug Fixes - bfb15a3 semantic: Make multi_index_vec clone panic-safe (oxc-project#19299) (Boshen) - 41c50a5 transformer: Ignore invalid JSX pragma identifiers (oxc-project#19296) (Boshen) - deed3d8 transformer: Remove unnecessary trailing expression in object rest spread assignment (oxc-project#19259) (Boshen) - 5bdaacc transformer: Propagate source spans for sourcemap correctness (oxc-project#19258) (Boshen) - 3e0e5ba isolated-declarations: Align readonly class array initializer diagnostics with tsc (oxc-project#19218) (camc314) ### ⚡ Performance - c169c77 syntax: Optimize `is_identifier_name_patched` (oxc-project#19386) (sapphi-red) - aa1e1a8 allocator: Inline BitSet accessors (oxc-project#19331) (Boshen) - 5b90d46 semantic: Improve SoA with multi index vec (oxc-project#19138) (Boshen) - 99ce2a6 isolated_declarations: Mark all diagnostic functions as `#[cold]` (oxc-project#19279) (camc314) - dd0220f transformer: Remove TS-only nodes earlier in `enter_statements` (oxc-project#19166) (Dunqing) - e5baf60 isolated-declarations: Replace hash collections with index-based Vec (oxc-project#19221) (Dunqing) ### 📚 Documentation - 569aa61 rust: Add missing rustdocs and remove missing_docs lint attrs (oxc-project#19306) (Boshen)
Summary
SPAN), so transformed nodes previously produced no sourcemap mappingsspan: Spanparameters to shared helpers (create_assignment,create_member_callee,create_prototype_member) and threaded spans through call chainsSPANfor truly synthetic nodes (generated temps, helper function internals, protocol boilerplate)🤖 Generated with Claude Code