-
-
Notifications
You must be signed in to change notification settings - Fork 30
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
ArrowFunctionExpression's scope is always strict scope #49
Comments
Thank you for the report! Sounds like a bug. |
mysticatea
pushed a commit
that referenced
this issue
Feb 22, 2019
not-an-aardvark
added a commit
that referenced
this issue
Mar 2, 2019
This reverts commit 2533966. The change is causing ESLint to crash with a parsing error on the following code: ```js console.log(this); z(x => console.log(x, this)) ``` ``` TypeError: Cannot read property 'length' of undefined at isStrictScope (/Users/tkatz/code/eslint/node_modules/eslint-scope/lib/scope.js:93:40) at new Scope (/Users/tkatz/code/eslint/node_modules/eslint-scope/lib/scope.js:254:25) at new FunctionScope (/Users/tkatz/code/eslint/node_modules/eslint-scope/lib/scope.js:641:9) at ScopeManager.__nestFunctionScope (/Users/tkatz/code/eslint/node_modules/eslint-scope/lib/scope-manager.js:209:33) at Referencer.visitFunction (/Users/tkatz/code/eslint/node_modules/eslint-scope/lib/referencer.js:200:27) at Referencer.ArrowFunctionExpression (/Users/tkatz/code/eslint/node_modules/eslint-scope/lib/referencer.js:567:14) at Referencer.Visitor.visit (/Users/tkatz/code/eslint/node_modules/esrecurse/esrecurse.js:104:34) at Referencer.Visitor.visitChildren (/Users/tkatz/code/eslint/node_modules/esrecurse/esrecurse.js:83:38) at Referencer.CallExpression (/Users/tkatz/code/eslint/node_modules/eslint-scope/lib/referencer.js:494:14) at Referencer.Visitor.visit (/Users/tkatz/code/eslint/node_modules/esrecurse/esrecurse.js:104:34) ``` Since this is currently affecting ESLint users, we're reverting the change for now until we figure out the root cause.
not-an-aardvark
added a commit
that referenced
this issue
Mar 2, 2019
This reverts commit 2533966. The change is causing ESLint to crash with a parsing error on the following code: ```js console.log(this); z(x => console.log(x, this)) ``` ``` TypeError: Cannot read property 'length' of undefined at isStrictScope (/Users/tkatz/code/eslint/node_modules/eslint-scope/lib/scope.js:93:40) at new Scope (/Users/tkatz/code/eslint/node_modules/eslint-scope/lib/scope.js:254:25) at new FunctionScope (/Users/tkatz/code/eslint/node_modules/eslint-scope/lib/scope.js:641:9) at ScopeManager.__nestFunctionScope (/Users/tkatz/code/eslint/node_modules/eslint-scope/lib/scope-manager.js:209:33) at Referencer.visitFunction (/Users/tkatz/code/eslint/node_modules/eslint-scope/lib/referencer.js:200:27) at Referencer.ArrowFunctionExpression (/Users/tkatz/code/eslint/node_modules/eslint-scope/lib/referencer.js:567:14) at Referencer.Visitor.visit (/Users/tkatz/code/eslint/node_modules/esrecurse/esrecurse.js:104:34) at Referencer.Visitor.visitChildren (/Users/tkatz/code/eslint/node_modules/esrecurse/esrecurse.js:83:38) at Referencer.CallExpression (/Users/tkatz/code/eslint/node_modules/eslint-scope/lib/referencer.js:494:14) at Referencer.Visitor.visit (/Users/tkatz/code/eslint/node_modules/esrecurse/esrecurse.js:104:34) ``` Since this is currently affecting ESLint users, we're reverting the change for now until we figure out the root cause.
Reopening because the fix was reverted (see #51) |
futpib
added a commit
to futpib/eslint-scope
that referenced
this issue
Mar 2, 2019
not-an-aardvark
pushed a commit
that referenced
this issue
Mar 15, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It seems to be deliberate that
eslint-scope
always setsisStrict
totrue
for arrow function scopes. But this is not how it works in all the engines I could get my hands to.I used assignment to an undeclared variable to check if the code is in strict mode:
With explicit strict mode, we get an error:
Without
"use strict"
an error is not thrown, which means it's not in strict mode, buteslint-scope
would treat the scope as strict anyway:node -e '(() => { x = 1 })()'
I also checked with the spec's definition of strict mode code, and it seems that arrow functions should not get any special treatment (only classes should): https://www.ecma-international.org/ecma-262/#sec-strict-mode-code
eslint-scope/lib/scope.js
Lines 52 to 55 in 3e69fdc
eslint-scope/tests/es6-arrow-function-expression.js
Line 55 in 3e69fdc
The text was updated successfully, but these errors were encountered: