reject invalid for await syntax (#4847)

This commit is contained in:
Alex Lam S.L
2021-04-07 15:37:15 +01:00
committed by GitHub
parent 73a564343b
commit a37ca558dd
3 changed files with 16 additions and 1 deletions

View File

@@ -1189,7 +1189,7 @@ function parse($TEXT, options) {
var await = is("name", "await") && next(); var await = is("name", "await") && next();
expect("("); expect("(");
var init = null; var init = null;
if (!is("punc", ";")) { if (await || !is("punc", ";")) {
init = is("keyword", "const") init = is("keyword", "const")
? (next(), const_(true)) ? (next(), const_(true))
: is("keyword", "let") : is("keyword", "let")

View File

@@ -0,0 +1 @@
for await (; console.log(42););

View File

@@ -679,6 +679,20 @@ describe("bin/uglifyjs", function() {
done(); 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) { it("Should throw syntax error (switch defaults)", function(done) {
var command = uglifyjscmd + " test/input/invalid/switch.js"; var command = uglifyjscmd + " test/input/invalid/switch.js";
exec(command, function(err, stdout, stderr) { exec(command, function(err, stdout, stderr) {