diff options
author | bcoe <bencoe@google.com> | 2020-02-24 06:19:15 +0300 |
---|---|---|
committer | Benjamin Coe <bencoe@google.com> | 2020-02-28 04:33:56 +0300 |
commit | fb26b136238240eeac1b3ede098e097a343aef0b (patch) | |
tree | 14b7aef45b22877a670b41833176492f044b1d39 /lib/internal/source_map | |
parent | a777cfa843d5b996e45c4f8188733b637594378b (diff) |
module: port source map sort logic from chromium
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: https://github.com/nodejs/node/pull/31927
Fixes: https://github.com/nodejs/node/issues/31286
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'lib/internal/source_map')
-rw-r--r-- | lib/internal/source_map/source_map.js | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/lib/internal/source_map/source_map.js b/lib/internal/source_map/source_map.js index c440dffdf81..acff068be2a 100644 --- a/lib/internal/source_map/source_map.js +++ b/lib/internal/source_map/source_map.js @@ -152,10 +152,12 @@ class SourceMap { * @param {SourceMapV3} mappingPayload */ #parseMappingPayload = () => { - if (this.#payload.sections) + if (this.#payload.sections) { this.#parseSections(this.#payload.sections); - else + } else { this.#parseMap(this.#payload, 0, 0); + } + this.#mappings.sort(compareSourceMapEntry); } /** @@ -321,6 +323,21 @@ function cloneSourceMapV3(payload) { return payload; } +/** + * @param {Array} entry1 source map entry [lineNumber, columnNumber, sourceURL, + * sourceLineNumber, sourceColumnNumber] + * @param {Array} entry2 source map entry. + * @return {number} + */ +function compareSourceMapEntry(entry1, entry2) { + const [lineNumber1, columnNumber1] = entry1; + const [lineNumber2, columnNumber2] = entry2; + if (lineNumber1 !== lineNumber2) { + return lineNumber1 - lineNumber2; + } + return columnNumber1 - columnNumber2; +} + module.exports = { SourceMap }; |