Skip to content
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

module: port source map sorting logic from chromium #31927

Closed
wants to merge 2 commits into from

Conversation

bcoe
Copy link
Contributor

@bcoe bcoe commented Feb 24, 2020

Digging in to the delta between V8's source map library, and chromium's
the most significant difference that jumped out at me was that we were
failing to sort generated columns. Since negative offsets are not
restricted in the spec, this can lead to bugs.

fixes: #31286


Reading through the Chromium source map implementation, this was the most significant logic that jumped out at me as missing. Given the number of additional dependencies Chromium's implementation has, I think we'd do better to fix this bug, and stick with the source map class we have.

@jridgewell does this logic look correct to you, I used your tests as a starting point.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

Digging in to the delta between V8's source map library, and chromium's
the most significant difference that jumped out at me was that we were
failing to sort generated columns. Since negative offsets are not
restricted in the spec, this can lead to bugs.

fixes: nodejs#31286
Copy link
Contributor

@jridgewell jridgewell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sections can also cause misordered line numbers:

this.#parseMap(section.map, section.offset.line, section.offset.column);

I would just unconditionally sort in parseMappingPayload, and let the sorting algorithm optimize. It's probably just an O(n) for already sorted.

if (columnOffset < 0) {
hadNegativeColumnOffset = true;
}
columnNumber += columnOffset;
if (isSeparator(stringCharIterator.peek())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How much can we clean up this code? The whole iterator string iterator wrapper thing is icky to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we've diverged quite a bit form the V8 implementation at this point, introducing private fields as an example. I probably wouldn't do it in this PR, but I think you could go ahead and refactor as much as you see fit.

function makeMinimalMap(generatedColumns, originalColumns) {
return {
sources: ['test.js'],
// Mapping from the 0th line, 0th column of the output file to the 0th
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Mapping from the 0th line, 0th column of the output file to the 0th
// Mapping from the 0th line, ${g}th column of the output file to the 0th

['U', 'F', 'F'],
['A', 'E', 'E']
));
assert.strictEqual(sourceMap.findEntry(0, 6).originalColumn, 4);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@nodejs-github-bot
Copy link
Collaborator

@bcoe bcoe added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Feb 27, 2020
bcoe added a commit that referenced this pull request Feb 28, 2020
Digging in to the delta between V8's source map library, and chromium's
the most significant difference that jumped out at me was that we were
failing to sort generated columns. Since negative offsets are not
restricted in the spec, this can lead to bugs.

fixes: #31286

PR-URL: #31927
Fixes: #31286
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
@bcoe
Copy link
Contributor Author

bcoe commented Feb 28, 2020

Landed in fb26b13

@bcoe bcoe closed this Feb 28, 2020
@bcoe bcoe deleted the sort-source-maps branch February 28, 2020 01:35
codebytere pushed a commit that referenced this pull request Feb 29, 2020
Digging in to the delta between V8's source map library, and chromium's
the most significant difference that jumped out at me was that we were
failing to sort generated columns. Since negative offsets are not
restricted in the spec, this can lead to bugs.

fixes: #31286

PR-URL: #31927
Fixes: #31286
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
@codebytere codebytere mentioned this pull request Feb 29, 2020
@targos
Copy link
Member

targos commented Apr 18, 2020

Depends on #31132 to land on v12.x

@targos targos added source maps Issues and PRs related to source map support. and removed author ready PRs that have at least one approval, no pending requests for changes, and a CI started. backport-blocked-v12.x labels Apr 25, 2020
targos pushed a commit to targos/node that referenced this pull request Apr 25, 2020
Digging in to the delta between V8's source map library, and chromium's
the most significant difference that jumped out at me was that we were
failing to sort generated columns. Since negative offsets are not
restricted in the spec, this can lead to bugs.

fixes: nodejs#31286

PR-URL: nodejs#31927
Fixes: nodejs#31286
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
targos pushed a commit that referenced this pull request Apr 28, 2020
Digging in to the delta between V8's source map library, and chromium's
the most significant difference that jumped out at me was that we were
failing to sort generated columns. Since negative offsets are not
restricted in the spec, this can lead to bugs.

fixes: #31286

PR-URL: #31927
Fixes: #31286
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
source maps Issues and PRs related to source map support.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

consider switching to Chromium's source-map implementation
6 participants