-
-
Notifications
You must be signed in to change notification settings - Fork 30
Is a class's heritage referenced from the wrong scope? #59
Comments
I think the only answer we can give here is we don't know. We forked escope in order to have a better way to get it updated to fit in with our release cycle, but we still don't know all the dark secrets contained within. |
It's not a huge deal ultimately - there's still a reference to it, and I don't think anyone consuming this package is explicitly asserting a reference comes from a specific scope. I was just working on a ground-up reimplementation which supports typescript (typescript-eslint/typescript-eslint#1939) and noticed this. I have some snapshot tests to validate the structure of the scope. When I added a snapshot test for the heritage, I noticed the placement of the reference and was confused. I was mainly hoping someone more familiar with the spec could tell me if I'm interpreting the JS spec correctly or not 😅 |
I'm sorry for my overlooked. I think @bradzacher is right. The references of the const A = class A extends A {} the third |
@mysticatea is this something you feel like addressing? If not, I can try to do it |
@nzakas are you maybe working on this? If not, I could take it. |
I'm not. Please feel free. |
I'm working on this. |
* fix!: class `extends` is evaluated in the class scope Fixes #59 * add tests with nested scopes
Am I misunderstanding the spec here?
I'm new to attempting to read the ECMAScript spec, so I wouldn't be surprised if I'm wrong...
To me it looks like the superclass is referenced from within the class's scope:
https://www.ecma-international.org/ecma-262/8.0/#sec-runtime-semantics-classdefinitionevaluation
lex
be theLexicalEnvironment
of the running execution context.classScope
beNewDeclarativeEnvironment(lex)
.className
is notundefined
, thena) ...
ClassHeritage_opt
is not present, thena) ...
a) Set the running execution context's
LexicalEnvironment
toclassScope
.b) Let
superclass
be the result of evaluatingClassHeritage
.c) ...
When
superclass
is evaluated, it is specifically withinclassScope
. So this means the reference should be placed within the class scope, right?However, the scope manager references the superclass before it nests the class scope (i.e. it is referenced from the parent's scope):
eslint-scope/lib/referencer.js
Lines 264 to 280 in dbddf14
I tried to dig through the old escope history, but there's no information attached to the commit (estools/escope@c3e23e2)
The text was updated successfully, but these errors were encountered: