-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Conversation
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
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.
sections
can also cause misordered line numbers:
node/lib/internal/source_map/source_map.js
Line 167 in 584bdd8
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())) { |
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.
How much can we clean up this code? The whole iterator string iterator wrapper thing is icky to me.
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.
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.
test/parallel/test-source-map-api.js
Outdated
function makeMinimalMap(generatedColumns, originalColumns) { | ||
return { | ||
sources: ['test.js'], | ||
// Mapping from the 0th line, 0th column of the output file to the 0th |
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.
// 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); |
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.
LGTM.
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>
Landed in fb26b13 |
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>
Depends on #31132 to land on v12.x |
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>
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>
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), orvcbuild test
(Windows) passes