From: Alex Lam S.L Date: Wed, 7 Apr 2021 14:37:15 +0000 (+0100) Subject: reject invalid `for await` syntax (#4847) X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=a37ca558dd8d7f5243e061e216287793b9108911;p=UglifyJS.git reject invalid `for await` syntax (#4847) --- diff --git a/lib/parse.js b/lib/parse.js index bc13b60e..323769a2 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 00000000..13e07607 --- /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 4d4972ec..5b84eba6 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) {