diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-04-07 15:37:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-07 22:37:15 +0800 |
commit | a37ca558dd8d7f5243e061e216287793b9108911 (patch) | |
tree | 6870fa7c80ed55abc6a416c6a763633685bcaaa2 | |
parent | 73a564343b8231f2278c37c00c444b2cac8e314d (diff) | |
download | tracifyjs-a37ca558dd8d7f5243e061e216287793b9108911.tar.gz tracifyjs-a37ca558dd8d7f5243e061e216287793b9108911.zip |
reject invalid `for await` syntax (#4847)
-rw-r--r-- | lib/parse.js | 2 | ||||
-rw-r--r-- | test/input/invalid/for-await.js | 1 | ||||
-rw-r--r-- | test/mocha/cli.js | 14 |
3 files changed, 16 insertions, 1 deletions
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) { |