Skip to content

Commit

Permalink
Fixed incorrect sourcemap generated by applySourceMap when the inital…
Browse files Browse the repository at this point in the history
… sourcemap has fewer mappings than the applied sourcemap

A->a  |  A->a  = A->a
B->b  |        = B->b
C->c  |        = C->c
D->d  |        = D->d

An existing test had to be changed since the way it describes inexact matching is no longer the correct way to do it
  • Loading branch information
Marius Gundersen authored and Marius Gundersen committed Oct 24, 2015
1 parent 0140f6d commit 6d40e0e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions lib/source-map-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@
line: mapping.originalLine,
column: mapping.originalColumn
});

var generated = aSourceMapConsumer.generatedPositionFor(original);
var diff = {line: mapping.originalLine - generated.line, column: mapping.originalColumn - generated.column};

if (original.source != null) {
// Copy mapping
mapping.source = original.source;
Expand All @@ -202,8 +206,8 @@
if (sourceRoot != null) {
mapping.source = util.relative(sourceRoot, mapping.source);
}
mapping.originalLine = original.line;
mapping.originalColumn = original.column;
mapping.originalLine = original.line + diff.line;
mapping.originalColumn = original.column + diff.column;
if (original.name != null) {
mapping.name = original.name;
}
Expand Down
2 changes: 1 addition & 1 deletion test/test-source-map-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@
});
expectedMap.addMapping({
generated: { line: 2, column: 4 },
original: { line: 1, column: 0 },
original: { line: 1, column: 4 },
source: 'original-source'
});

Expand Down

0 comments on commit 6d40e0e

Please sign in to comment.