shapesecurity / shift-parser-js

ECMAScript parser that produces a Shift format AST
http://shift-ast.org/parser.html
Apache License 2.0
248 stars 28 forks source link

Rejects `let` as for-statement body #389

Closed bakkot closed 5 years ago

bakkot commented 5 years ago

See this test.

for (; false; ) let
{}

is a perfectly valid program: it is a for statement whose body is an ExpressionStatement consisting of an IdentifierExpression, followed by an empty block.

Because there is no lookahead restriction for let { for ExpressionStatements it can start parsing as one, and because there is no valid parse beginning for (; false; ) let \n { (unlike at the top level of a script), ASI kicks in after the let.

bakkot commented 5 years ago

Ditto for

for (; false; ) let
x = 0;
for (var x in null) let
{}
for (var x in null) let
x = 0;
for (var x of []) let
{}
for (var x of []) let
x = 0
if (false) let
{}
if (false) let
x = 0
l: let
{}
l: let
x = 0
with ({}) let
{}
with ({}) let
x = 0
while (false) let
{}
while (false) let
x = 0
Protryon commented 5 years ago

Addressed by #396.