Skip to content

Commit

Permalink
ignore invalid mappings
Browse files Browse the repository at this point in the history
Fixes #1 Mappings with no source cause a crash
  • Loading branch information
floridoo committed Jul 12, 2014
1 parent 7592e2c commit 2bc7466
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
26 changes: 14 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,20 @@ Concat.prototype.add = function(filePath, content, sourceMap) {
var upstreamSM = new SourceMapConsumer(sourceMap);
var _this = this;
upstreamSM.eachMapping(function(mapping) {
_this._sourceMap.addMapping({
generated: {
line: _this.lineOffset + mapping.generatedLine,
column: (mapping.generatedLine === 1 ? _this.columnOffset : 0) + mapping.generatedColumn
},
original: {
line: mapping.originalLine,
column: mapping.originalColumn
},
source: mapping.source,
name: mapping.name
});
if (mapping.source) {
_this._sourceMap.addMapping({
generated: {
line: _this.lineOffset + mapping.generatedLine,
column: (mapping.generatedLine === 1 ? _this.columnOffset : 0) + mapping.generatedColumn
},
original: {
line: mapping.originalLine,
column: mapping.originalColumn
},
source: mapping.source,
name: mapping.name
});
}
});
if (upstreamSM.sourcesContent) {
upstreamSM.sourcesContent.forEach(function(sourceContent, i) {
Expand Down
21 changes: 21 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ function testCase(description, options) {
t.equal(concat.content, options.output.content, 'should produce the right output');
if (options.output.sourceMap)
t.deepEqual(JSON.parse(concat.sourceMap), JSON.parse(options.output.sourceMap), 'should produce the right source map');
else
t.equal(concat.sourceMap, undefined, 'should not produce a source map');
t.end();
});
}
Expand Down Expand Up @@ -232,3 +234,22 @@ testCase('should pass on source content when mappings is empty', {
sourceMap: '{"version":3,"file":"out.js","sources":["intermediate.js","test2","test3"],"names":[],"mappings":"AAAA;ACAA;ACAA","sourcesContent":["AAA",null,null]}'
}
});

testCase('should ignore invalid mappings', {
separator: '\n',
sourceMapping: true,
outFile: 'out.js',
input: [
{
content: 'AAA\nBBB\nCCC',
sourceMap: '{"version":3,"file":"intermediate.js","sources":["test11","test12","test13"], "sourcesContent": ["AAA", "BBB", "CCC"], "names":[],"mappings":"A;ACAA;ACAA"}',
fileName: 'intermediate.js'
},
{ content: 'EEE' },
{ content: 'FFF' }
],
output: {
content: 'AAA\nBBB\nCCC\nEEE\nFFF',
sourceMap: '{"version":3,"file":"out.js","sources":["test12","test13","test2","test3"],"names":[],"mappings":";AAAA;ACAA;ACAA;ACAA","sourcesContent":["BBB","CCC",null,null]}'
}
});

0 comments on commit 2bc7466

Please sign in to comment.