From b4b9305db0d3c4682848ed0a4214f1fee332a078 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Wed, 19 Apr 2017 04:27:13 +0800 Subject: fix parser bugs & CLI reporting (#1827) fixes #1825 --- test/input/invalid/assign_4.js | 1 + test/input/invalid/dot_1.js | 1 + test/input/invalid/dot_2.js | 1 + test/input/invalid/dot_3.js | 1 + test/input/invalid/object.js | 1 + test/mocha/cli.js | 79 ++++++++++++++++++++++++++++++++++++++++-- 6 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 test/input/invalid/assign_4.js create mode 100644 test/input/invalid/dot_1.js create mode 100644 test/input/invalid/dot_2.js create mode 100644 test/input/invalid/dot_3.js create mode 100644 test/input/invalid/object.js (limited to 'test') diff --git a/test/input/invalid/assign_4.js b/test/input/invalid/assign_4.js new file mode 100644 index 00000000..d4d6b113 --- /dev/null +++ b/test/input/invalid/assign_4.js @@ -0,0 +1 @@ +++null diff --git a/test/input/invalid/dot_1.js b/test/input/invalid/dot_1.js new file mode 100644 index 00000000..7c4f3a66 --- /dev/null +++ b/test/input/invalid/dot_1.js @@ -0,0 +1 @@ +a.= diff --git a/test/input/invalid/dot_2.js b/test/input/invalid/dot_2.js new file mode 100644 index 00000000..32c027f8 --- /dev/null +++ b/test/input/invalid/dot_2.js @@ -0,0 +1 @@ +%.a; diff --git a/test/input/invalid/dot_3.js b/test/input/invalid/dot_3.js new file mode 100644 index 00000000..65573828 --- /dev/null +++ b/test/input/invalid/dot_3.js @@ -0,0 +1 @@ +a./(); diff --git a/test/input/invalid/object.js b/test/input/invalid/object.js new file mode 100644 index 00000000..46216d81 --- /dev/null +++ b/test/input/invalid/object.js @@ -0,0 +1 @@ +console.log({%: 1}); diff --git a/test/mocha/cli.js b/test/mocha/cli.js index 7162c816..697c09a3 100644 --- a/test/mocha/cli.js +++ b/test/mocha/cli.js @@ -296,14 +296,89 @@ describe("bin/uglifyjs", function () { assert.ok(err); assert.strictEqual(stdout, ""); assert.strictEqual(stderr.split(/\n/).slice(0, 4).join("\n"), [ - "Parse error at test/input/invalid/assign_3.js:1,18", + "Parse error at test/input/invalid/assign_3.js:1,17", "console.log(3 || ++this);", - " ^", + " ^", + "ERROR: Invalid use of ++ operator" + ].join("\n")); + done(); + }); + }); + it("Should throw syntax error (++null)", function(done) { + var command = uglifyjscmd + ' test/input/invalid/assign_4.js'; + + exec(command, function (err, stdout, stderr) { + assert.ok(err); + assert.strictEqual(stdout, ""); + assert.strictEqual(stderr.split(/\n/).slice(0, 4).join("\n"), [ + "Parse error at test/input/invalid/assign_4.js:1,0", + "++null", + "^", "ERROR: Invalid use of ++ operator" ].join("\n")); done(); }); }); + it("Should throw syntax error (a.=)", function(done) { + var command = uglifyjscmd + ' test/input/invalid/dot_1.js'; + + exec(command, function (err, stdout, stderr) { + assert.ok(err); + assert.strictEqual(stdout, ""); + assert.strictEqual(stderr.split(/\n/).slice(0, 4).join("\n"), [ + "Parse error at test/input/invalid/dot_1.js:1,2", + "a.=", + " ^", + "ERROR: Unexpected token: operator (=)" + ].join("\n")); + done(); + }); + }); + it("Should throw syntax error (%.a)", function(done) { + var command = uglifyjscmd + ' test/input/invalid/dot_2.js'; + + exec(command, function (err, stdout, stderr) { + assert.ok(err); + assert.strictEqual(stdout, ""); + assert.strictEqual(stderr.split(/\n/).slice(0, 4).join("\n"), [ + "Parse error at test/input/invalid/dot_2.js:1,0", + "%.a;", + "^", + "ERROR: Unexpected token: operator (%)" + ].join("\n")); + done(); + }); + }); + it("Should throw syntax error (a./();)", function(done) { + var command = uglifyjscmd + ' test/input/invalid/dot_3.js'; + + exec(command, function (err, stdout, stderr) { + assert.ok(err); + assert.strictEqual(stdout, ""); + assert.strictEqual(stderr.split(/\n/).slice(0, 4).join("\n"), [ + "Parse error at test/input/invalid/dot_3.js:1,2", + "a./();", + " ^", + "ERROR: Unexpected token: operator (/)" + ].join("\n")); + done(); + }); + }); + it("Should throw syntax error ({%: 1})", function(done) { + var command = uglifyjscmd + ' test/input/invalid/object.js'; + + exec(command, function (err, stdout, stderr) { + assert.ok(err); + assert.strictEqual(stdout, ""); + assert.strictEqual(stderr.split(/\n/).slice(0, 4).join("\n"), [ + "Parse error at test/input/invalid/object.js:1,13", + "console.log({%: 1});", + " ^", + "ERROR: Unexpected token: operator (%)" + ].join("\n")); + done(); + }); + }); it("Should handle literal string as source map input", function(done) { var command = [ uglifyjscmd, -- cgit v1.2.3