diff --git a/index.js b/index.js index 24f90c5..74e2e39 100644 --- a/index.js +++ b/index.js @@ -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({ diff --git a/package.json b/package.json index ef87b2a..3e7d1b7 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" } diff --git a/test/index.js b/test/index.js index 327c0bb..01db578 100644 --- a/test/index.js +++ b/test/index.js @@ -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"}' + } +});