diff options
author | Michael Mior <michael.mior@gmail.com> | 2017-03-09 14:08:43 -0500 |
---|---|---|
committer | Alex Lam S.L <alexlamsl@gmail.com> | 2017-03-10 03:08:43 +0800 |
commit | 93cdb194f4895384b68a66736366659c39caece8 (patch) | |
tree | e8f9746685ddbd31e898c9a8d4a9bd3a99ae111d | |
parent | b633706ce42576b7e2aa85a96c5691bde87e71ac (diff) | |
download | tracifyjs-93cdb194f4895384b68a66736366659c39caece8.tar.gz tracifyjs-93cdb194f4895384b68a66736366659c39caece8.zip |
Correctly raise a parse exception with a missing loop body (#1585)
-rw-r--r-- | lib/parse.js | 2 | ||||
-rw-r--r-- | test/input/invalid/loop-no-body.js | 1 | ||||
-rw-r--r-- | test/mocha/cli.js | 13 |
3 files changed, 16 insertions, 0 deletions
diff --git a/lib/parse.js b/lib/parse.js index 9aadc9f5..5e140862 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -787,6 +787,8 @@ function parse($TEXT, options) { return function() { var start = S.token; var expr = parser(); + if (!expr) croak("Expected expression"); + var end = prev(); expr.start = start; expr.end = end; diff --git a/test/input/invalid/loop-no-body.js b/test/input/invalid/loop-no-body.js new file mode 100644 index 00000000..07b27428 --- /dev/null +++ b/test/input/invalid/loop-no-body.js @@ -0,0 +1 @@ +for (var i = 0; i < 1; i++) diff --git a/test/mocha/cli.js b/test/mocha/cli.js index e8e07cb5..0b4fe007 100644 --- a/test/mocha/cli.js +++ b/test/mocha/cli.js @@ -238,4 +238,17 @@ describe("bin/uglifyjs", function () { done(); }); }); + it("Should fail with a missing loop body", function(done) { + var command = uglifyjscmd + ' test/input/invalid/loop-no-body.js'; + + exec(command, function (err, stdout, stderr) { + assert.ok(err); + var lines = stderr.split(/\n/); + assert.strictEqual(lines[0], "Parse error at test/input/invalid/loop-no-body.js:2,0"); + assert.strictEqual(lines[1], "for (var i = 0; i < 1; i++) "); + assert.strictEqual(lines[2], " ^"); + assert.strictEqual(lines[3], "SyntaxError: Expected expression"); + done(); + }); + }); }); |