reject invalid for await syntax (#4847)
This commit is contained in:
@@ -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")
|
||||||
|
|||||||
1
test/input/invalid/for-await.js
Normal file
1
test/input/invalid/for-await.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
for await (; console.log(42););
|
||||||
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user