diff --git a/lib/parse.js b/lib/parse.js index bc13b60ebd..323769a2d8 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -1189,7 +1189,7 @@ function parse($TEXT, options) { var await = is("name", "await") && next(); expect("("); var init = null; - if (!is("punc", ";")) { + if (await || !is("punc", ";")) { init = is("keyword", "const") ? (next(), const_(true)) : is("keyword", "let") diff --git a/test/input/invalid/for-await.js b/test/input/invalid/for-await.js new file mode 100644 index 0000000000..13e0760752 --- /dev/null +++ b/test/input/invalid/for-await.js @@ -0,0 +1 @@ +for await (; console.log(42);); diff --git a/test/mocha/cli.js b/test/mocha/cli.js index 4d4972ec1c..5b84eba6bb 100644 --- a/test/mocha/cli.js +++ b/test/mocha/cli.js @@ -679,6 +679,20 @@ describe("bin/uglifyjs", function() { done(); }); }); + it("Should throw syntax error (for-await)", function(done) { + var command = uglifyjscmd + " test/input/invalid/for-await.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/for-await.js:1,11", + "for await (; console.log(42););", + " ^", + "ERROR: Unexpected token: punc «;»", + ].join("\n")); + done(); + }); + }); it("Should throw syntax error (switch defaults)", function(done) { var command = uglifyjscmd + " test/input/invalid/switch.js"; exec(command, function(err, stdout, stderr) {