diff options
-rw-r--r-- | lib/minify.js | 6 | ||||
-rw-r--r-- | test/mocha/cli.js | 12 |
2 files changed, 17 insertions, 1 deletions
diff --git a/lib/minify.js b/lib/minify.js index 8e4aded9..8dc275cf 100644 --- a/lib/minify.js +++ b/lib/minify.js @@ -165,7 +165,11 @@ function minify(files, options) { if (!HOP(options.output, "code") || options.output.code) { if (options.sourceMap) { if (typeof options.sourceMap.content == "string") { - options.sourceMap.content = JSON.parse(options.sourceMap.content); + try { + options.sourceMap.content = JSON.parse(options.sourceMap.content); + } catch (ex) { + throw new Error("invalid input source map: " + options.sourceMap.content); + } } options.output.source_map = SourceMap({ file: options.sourceMap.filename, diff --git a/test/mocha/cli.js b/test/mocha/cli.js index 10f0465a..7f0bd79f 100644 --- a/test/mocha/cli.js +++ b/test/mocha/cli.js @@ -56,6 +56,18 @@ describe("bin/uglifyjs", function () { done(); }); }); + it("Should give sensible error against invalid input source map", function(done) { + var command = uglifyjscmd + " test/mocha.js --source-map content=blah,url=inline"; + + exec(command, function (err, stdout, stderr) { + assert.ok(err); + assert.deepEqual(stderr.split(/\n/).slice(0, 2), [ + "INFO: Using input source map: blah", + "ERROR: invalid input source map: blah", + ]); + done(); + }); + }); it("Should append source map to output when using --source-map url=inline", function (done) { var command = uglifyjscmd + " test/input/issue-1323/sample.js --source-map url=inline"; |