Skip to content

Commit 93cdb19

Browse files
michaelmioralexlamsl
authored andcommitted
Correctly raise a parse exception with a missing loop body (#1585)
1 parent b633706 commit 93cdb19

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

lib/parse.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,8 @@ function parse($TEXT, options) {
787787
return function() {
788788
var start = S.token;
789789
var expr = parser();
790+
if (!expr) croak("Expected expression");
791+
790792
var end = prev();
791793
expr.start = start;
792794
expr.end = end;

test/input/invalid/loop-no-body.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
for (var i = 0; i < 1; i++)

test/mocha/cli.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,4 +238,17 @@ describe("bin/uglifyjs", function () {
238238
done();
239239
});
240240
});
241+
it("Should fail with a missing loop body", function(done) {
242+
var command = uglifyjscmd + ' test/input/invalid/loop-no-body.js';
243+
244+
exec(command, function (err, stdout, stderr) {
245+
assert.ok(err);
246+
var lines = stderr.split(/\n/);
247+
assert.strictEqual(lines[0], "Parse error at test/input/invalid/loop-no-body.js:2,0");
248+
assert.strictEqual(lines[1], "for (var i = 0; i < 1; i++) ");
249+
assert.strictEqual(lines[2], " ^");
250+
assert.strictEqual(lines[3], "SyntaxError: Expected expression");
251+
done();
252+
});
253+
});
241254
});

0 commit comments

Comments
 (0)