Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

for-in cannot be parsed #116

Closed
neumatho opened this issue Oct 21, 2020 · 4 comments · Fixed by #118
Closed

for-in cannot be parsed #116

neumatho opened this issue Oct 21, 2020 · 4 comments · Fixed by #118

Comments

@neumatho
Copy link

The following for-in statement cannot be parsed in Meriyah, but works fine in Acorn. The Chrome browser can also parse it when entering it in the console window.

for(var a = /a/ in []);

-Thomas

@3cp
Copy link
Member

3cp commented Oct 23, 2020

@3cp
Copy link
Member

3cp commented Oct 23, 2020

Found some trouble, it seems there are some js features (for example let) implicitly turn on strict mode.

In node:

> for(var a = /a/ in []);
undefined

> for(let a = /a/ in []);
for(let a = /a/ in []);
        ^^^^^^^

Uncaught SyntaxError: for-in loop variable declaration may not have an initializer.
> 

@3cp
Copy link
Member

3cp commented Oct 23, 2020

I could find the case in ECMA2020 spec about let turning on strict mode. Maybe it's a nodejs/v8 deviation from spec? @KFlash

10.2.1 Strict Mode Code
An ECMAScript Script syntactic unit may be processed using either unrestricted or strict mode syntax and semantics. Code is interpreted as strict mode code in the following situations:

Global code is strict mode code if it begins with a Directive Prologue that contains a Use Strict Directive.
Module code is always strict mode code.
All parts of a ClassDeclaration or a ClassExpression are strict mode code.
Eval code is strict mode code if it begins with a Directive Prologue that contains a Use Strict Directive or if the call to eval is a direct eval that is contained in strict mode code.
Function code is strict mode code if the associated FunctionDeclaration, FunctionExpression, GeneratorDeclaration, GeneratorExpression, AsyncFunctionDeclaration, AsyncFunctionExpression, AsyncGeneratorDeclaration, AsyncGeneratorExpression, MethodDefinition, ArrowFunction, or AsyncArrowFunction is contained in strict mode code or if the code that produces the value of the function's [[ECMAScriptCode]] internal slot begins with a Directive Prologue that contains a Use Strict Directive.
Function code that is supplied as the arguments to the built-in Function, Generator, AsyncFunction, and AsyncGenerator constructors is strict mode code if the last argument is a String that when processed is a FunctionBody that begins with a Directive Prologue that contains a Use Strict Directive.

@3cp
Copy link
Member

3cp commented Oct 24, 2020

Add ref: while for-in error only applies in strict mode, for-of error is universal.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Invalid_for-of_initializer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants