Correctly raise a parse exception with a missing loop body (#1585)

This commit is contained in:
Michael Mior
2017-03-09 14:08:43 -05:00
committed by Alex Lam S.L
parent b633706ce4
commit 93cdb194f4
3 changed files with 16 additions and 0 deletions

View File

@@ -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;

View File

@@ -0,0 +1 @@
for (var i = 0; i < 1; i++)

View File

@@ -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();
});
});
});