Skip to content

Commit

Permalink
Fix crash when input source map has no mappings and no sources
Browse files Browse the repository at this point in the history
Fixes #5
  • Loading branch information
floridoo committed Nov 8, 2014
1 parent ca7ea5f commit 4063427
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Concat.prototype.add = function(filePath, content, sourceMap) {
});
}
} else {
if (sourceMap && sourceMap.sources)
if (sourceMap && sourceMap.sources && sourceMap.sources.length > 0)
filePath = sourceMap.sources[0];
for (var i = 1; i <= lines; i++) {
this._sourceMap.addMapping({
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "concat-with-sourcemaps",
"version": "0.1.5",
"version": "0.1.6",
"description": "Concatenate file contents with a custom separator and generate a source map",
"homepage": "http://github.com/floridoo/concat-with-sourcemaps",
"repository": "git://github.com/floridoo/concat-with-sourcemaps.git",
Expand All @@ -22,9 +22,9 @@
},
"devDependencies": {
"jshint": "^2.5.0",
"tape": "^2.12.3",
"tape": "^3.0.2",
"argg": "0.0.1",
"istanbul": "^0.2.8",
"istanbul": "^0.3.2",
"faucet": "0.0.1",
"coveralls": "^2.10.0"
}
Expand Down
19 changes: 19 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,22 @@ testCase('should keep source in sources with empty mappings', {
sourceMap: '{"version":3,"file":"out.js","sources":["testXXX","test2","test3"],"names":[],"mappings":"AAAA;ACAA;ACAA"}'
}
});

testCase('should not crash with an input source map with no mappings', {
separator: '\n',
sourceMapping: true,
outFile: 'out.js',
input: [
{
content: 'AAA\nBBB\nCCC',
sourceMap: '{"version":3,"file":"intermediate.js","sources":[],"names":[],"mappings":""}',
fileName: 'intermediate.js'
},
{ content: 'EEE' },
{ content: 'FFF' }
],
output: {
content: 'AAA\nBBB\nCCC\nEEE\nFFF',
sourceMap: '{"version":3,"file":"out.js","sources":["intermediate.js", "test2", "test3"],"names":[],"mappings":"AAAA;AACA;AACA;ACFA;ACAA"}'
}
});

0 comments on commit 4063427

Please sign in to comment.