Rebase React Compiler loc.index on real source-file start to fix span inversion across shared SourceMaps - #7
Draft
mattcosta7 with Copilot wants to merge 2 commits into
Draft
Conversation
Co-authored-by: mattcosta7 <8616962+mattcosta7@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix span calculation in ReverseCtx from review comments
Rebase React Compiler Aug 6, 2026
loc.index on real source-file start to fix span inversion across shared SourceMaps
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.
This addresses incorrect span reconstruction when React-Compiler-mutated nodes fall back to
loc: forward conversion treated offsets as if every file started atBytePos(1), and reverse conversion rebased using a file start derived fromprogram.span().lo. In multi-fileSourceMaps and files with leading trivia/shebang, this broke source-map fidelity and could push recovered spans out of file bounds.Forward conversion basis is now explicit and file-correct
source_file_start_pos: BytePostoConvertCtxandConvertResult, passed explicitly intoconvert_program.ConvertCtx::positionnow computes file-relative indices via:BaseNode.start/end/node_id= absolute SWCBytePosloc.line/column/index= Babel-style file-relative locationReverse fallback keeps exact inverse semantics
span_from_basefallback logic (source_file_start_pos + BytePos(index)) unchanged.start/endand file-relativeloc.index.API and caller plumbing now use real
SourceFile.start_postransform/lintnow acceptsource_file_start_pos: BytePos.transform_source/lint_sourceand parser helpers.crates/swc, fixture harness, example binary) to pass actual file start, avoiding silentBytePos(1)assumptions.Regression coverage for failure modes
loc-onlyindex == 0recovers file start)SourceMapsecond-file transform (recovered mappings stay within that file’s range)BytePos(1)round-trip invariant (absolute == start_pos + loc.index)