Repository navigation
sourcemap: pass the real source count to the mappings decoder #47240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
robobun
wants to merge
3
commits into
main
Choose a base branch
from
robobun/fba4fb53/source-index-bound
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 (optional) Users running a prebuilt
// @ bunfile whose map has one segment pastsourcesnow lose remapping for every frame in that file, with awarn:line, where main remapped the in-range frames. src/sourcemap/lib.rs:954 passessources.len()tomapping::parse, and Mapping.rs:582 refuses the whole map on the first out-of-range index, so get_source_map_impl returns None at lib.rs:552 and SavedSourceMap.rs:329 drops the entry for good. Node leaves only the bad frame unmapped. Fix: match node per frame: letparsekeep the map and haveLookup::display_source_url_if_needed/get_source_codereturn None for an out-of-rangesource_index(the guard this PR deletes at Mapping.rs:386), or at least keep acceptingsources: []maps.Why this was flagged
Trigger: any JSON map reachable through
parse_json(lib.rs:447 inline, :468 dev-server provider, :493 registered, :538<file>.mapon disk) in which at least one 4- or 5-field segment names an index >=sources.length, or whosesourcesis[]whilemappingscarries 4-field segments. On the base commitparse_jsonpassedi32::MAX(lib.rs:954 old), the map parsed, in-range frames were remapped to their original file and only the bad frame printed a mixed position. After this change Mapping.rs:582 returnsInvalidSourceIndexValuefor the first bad segment, lib.rs:545-552 warnsCould not decode sourcemap in '<file>': InvalidSourceIndexValueand returns None, and SavedSourceMap.rs:329-338 removes the entry so the file is never retried: every stack trace,Bun.inspect(error)preview, andbun test --coveragelookup for that file stays at built positions for the life of the process. A per-frame guard (the one deleted at Mapping.rs:386, plus the kept one at Mapping.rs:321) would reject only the bad frame as node does.Verification: src/sourcemap/lib.rs:954 now passes
i32::try_from(sources_paths.items().len()).unwrap_or(i32::MAX)where the base passedi32::MAX. src/sourcemap/Mapping.rs:582-589 returnsErr(ParseFail { err: InvalidSourceIndexValue })on the first out-of-range index, and src/jsc/SavedSourceMap.rs:327-333 removes the table entry, so no frame in that file is remapped for the rest of the process.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not changed. The guard you suggest is what
maindoes today, and it is the cause of the mixed frame.display_source_url_if_neededreturnsNonefor an index past the names (Mapping.rs:321). The three remap sites inVirtualMachine.rsthen keep the built URL and still copy the original line and column. That printsentry.js:5:3.A verdict for each frame needs more than that guard. Every reader of a lookup has to treat the mapping as absent: the three remap sites, coverage, and the content pick in
parse_json. Or the decoder has to mark the row. Both add a branch to each lookup, for every map.The whole-map refusal is what this decoder already does for a negative source index, a negative line or column, and a bad VLQ.
new module.SourceMappasses its real count to the same decoder and throws.Reach: 0 of 542 bun-built maps from npm packages have such a row, and 0 of 192 maps from
bun build. 2 of 8,111.mapfiles in the checkout have one. Both are invalid-map fixtures of the tc39 suite.For
sources: []with 4-field mappings, every frame of that file is a mixed frame onmain. Node leaves those frames unmapped. With this PR they are unmapped too, with one warning.The cost is the first Downsides bullet: the in-range frames of such a map are no longer remapped. I leave this thread open so that a maintainer can decide.