| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6a35b0d commit 9e3e676
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -152,10 +152,12 @@ class SourceMap { | |||
| 152 | 152 | * @param {SourceMapV3} mappingPayload | |
| 153 | 153 | */ | |
| 154 | 154 | #parseMappingPayload = () => { | |
| 155 | - if (this.#payload.sections) | ||
| 155 | + if (this.#payload.sections) { | ||
| 156 | 156 | this.#parseSections(this.#payload.sections); | |
| 157 | - else | ||
| 157 | + } else { | ||
| 158 | 158 | this.#parseMap(this.#payload, 0, 0); | |
| 159 | + } | ||
| 160 | + this.#mappings.sort(compareSourceMapEntry); | ||
| 159 | 161 | } | |
| 160 | 162 | ||
| 161 | 163 | /** | |
@@ -321,6 +323,21 @@ function cloneSourceMapV3(payload) { | |||
| 321 | 323 | return payload; | |
| 322 | 324 | } | |
| 323 | 325 | ||
| 326 | + /** | ||
| 327 | + * @param {Array} entry1 source map entry [lineNumber, columnNumber, sourceURL, | ||
| 328 | + * sourceLineNumber, sourceColumnNumber] | ||
| 329 | + * @param {Array} entry2 source map entry. | ||
| 330 | + * @return {number} | ||
| 331 | + */ | ||
| 332 | + function compareSourceMapEntry(entry1, entry2) { | ||
| 333 | + const [lineNumber1, columnNumber1] = entry1; | ||
| 334 | + const [lineNumber2, columnNumber2] = entry2; | ||
| 335 | + if (lineNumber1 !== lineNumber2) { | ||
| 336 | + return lineNumber1 - lineNumber2; | ||
| 337 | + } | ||
| 338 | + return columnNumber1 - columnNumber2; | ||
| 339 | + } | ||
| 340 | + | ||
| 324 | 341 | module.exports = { | |
| 325 | 342 | SourceMap | |
| 326 | 343 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -124,3 +124,28 @@ const { readFileSync } = require('fs'); | |||
| 124 | 124 | assert.strictEqual(originalColumn, knownDecodings[column]); | |
| 125 | 125 | } | |
| 126 | 126 | } | |
| 127 | + | ||
| 128 | + // Test that generated columns are sorted when a negative offset is | ||
| 129 | + // observed, see: https://github.com/mozilla/source-map/pull/92 | ||
| 130 | + { | ||
| 131 | + function makeMinimalMap(generatedColumns, originalColumns) { | ||
| 132 | + return { | ||
| 133 | + sources: ['test.js'], | ||
| 134 | + // Mapping from the 0th line, ${g}th column of the output file to the 0th | ||
| 135 | + // source file, 0th line, ${column}th column. | ||
| 136 | + mappings: generatedColumns.map((g, i) => `${g}AA${originalColumns[i]}`) | ||
| 137 | + .join(',') | ||
| 138 | + }; | ||
| 139 | + } | ||
| 140 | + // U = 10 | ||
| 141 | + // F = -2 | ||
| 142 | + // A = 0 | ||
| 143 | + // E = 2 | ||
| 144 | + const sourceMap = new SourceMap(makeMinimalMap( | ||
| 145 | + ['U', 'F', 'F'], | ||
| 146 | + ['A', 'E', 'E'] | ||
| 147 | + )); | ||
| 148 | + assert.strictEqual(sourceMap.findEntry(0, 6).originalColumn, 4); | ||
| 149 | + assert.strictEqual(sourceMap.findEntry(0, 8).originalColumn, 2); | ||
| 150 | + assert.strictEqual(sourceMap.findEntry(0, 10).originalColumn, 0); | ||
| 151 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments