Skip to content

Commit

Permalink
reject invalid for await syntax (#4847)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlamsl committed Apr 7, 2021
1 parent 73a5643 commit a37ca55
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/parse.js
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions test/input/invalid/for-await.js
@@ -0,0 +1 @@
for await (; console.log(42););
14 changes: 14 additions & 0 deletions test/mocha/cli.js
Expand Up @@ -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) {
Expand Down

0 comments on commit a37ca55

Please sign in to comment.