diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2018-03-31 18:48:20 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-31 18:48:20 +0900 |
commit | 02f47e1713cb413ac0d2602039c18292f43db863 (patch) | |
tree | c80e7fb999a2bb5c71192a6b627b4c4d4f725066 | |
parent | 07f64d4050cd28cf2a837d30ce2938fa9628ff57 (diff) | |
download | tracifyjs-02f47e1713cb413ac0d2602039c18292f43db863.tar.gz tracifyjs-02f47e1713cb413ac0d2602039c18292f43db863.zip |
give sensible error against invalid input source map (#3044)
-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"; |