Skip to content

Commit

Permalink
devtools: don't assume monotonic mappings in SDK.TextSourceMap._parseMap
Browse files Browse the repository at this point in the history
Some nasty source maps generated by ClojureScript really use negative
indices.

issue #53
  • Loading branch information
darwin committed Feb 2, 2017
1 parent e03cb3f commit adba577
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions resources/unpacked/devtools/front_end/sdk/SourceMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,23 @@ SDK.TextSourceMap = class {
this._mappings.push(new SDK.SourceMapEntry(
lineNumber, columnNumber, sourceURL, sourceLineNumber, sourceColumnNumber, names[nameIndex]));
}

// we have to sort the mappings for findEntry
// some source maps don't have monotonic mappings,
// _decodeVLQ might return negative values when updating columnNumber
// AFAIK, spec here does not disallow it:
// https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit
this._mappings.sort((a, b) => {
const al = a.lineNumber;
const bl = b.lineNumber;
const ac = a.columnNumber;
const bc = b.columnNumber;
if (al < bl || (al === bl && ac < bc)) {
return -1;
} else {
return 1;
}
});
}

/**
Expand Down

0 comments on commit adba577

Please sign in to comment.