javascript - let in if without braces -
if (true) { let x = 5 }
works expected (no syntax error), but
if (true) let x = 5
throws syntaxerror: unexpected strict mode reserved word
in node 4.1.0 , babel
is expected behavior? know stupid example. i'm wondering wether bug or not.
yes expected behavior. the production rule of if
statement
if ( expression[in, ?yield] ) statement[?yield, ?return]
but let
declaration is not statement
, therefore not allowed in position:
statement[yield, return] : blockstatement[?yield, ?return] variablestatement[?yield] emptystatement expressionstatement[?yield] ifstatement[?yield, ?return] breakablestatement[?yield, ?return] continuestatement[?yield] breakstatement[?yield] [+return] returnstatement[?yield] withstatement[?yield, ?return] labelledstatement[?yield, ?return] throwstatement[?yield] trystatement[?yield, ?return] debuggerstatement declaration[yield] : hoistabledeclaration[?yield] classdeclaration[?yield] lexicaldeclaration[in, ?yield] lexicaldeclaration[in, yield] : letorconst bindinglist[?in, ?yield] ;
Comments
Post a Comment