You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently parsing any code module expression and analyzing the scope will lead to an error:
AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:
assert(this.__currentScope === null)
at ScopeManager.__nestScope (project/node_modules/.pnpm/eslint-scope@5.1.1/node_modules/eslint-scope/lib/scope-manager.js:193:13)
at ScopeManager.__nestGlobalScope (project/node_modules/.pnpm/eslint-scope@5.1.1/node_modules/eslint-scope/lib/scope-manager.js:201:21)
at Referencer.Program (project/node_modules/.pnpm/eslint-scope@5.1.1/node_modules/eslint-scope/lib/referencer.js:412:27)
at Referencer.Visitor.visit (project/node_modules/.pnpm/esrecurse@4.3.0/node_modules/esrecurse/esrecurse.js:104:34)
at Referencer.Visitor.visitChildren (project/node_modules/.pnpm/esrecurse@4.3.0/node_modules/esrecurse/esrecurse.js:88:26)
at Referencer.Visitor.visit (project/node_modules/.pnpm/esrecurse@4.3.0/node_modules/esrecurse/esrecurse.js:107:14)
at Referencer.VariableDeclaration (project/node_modules/.pnpm/eslint-scope@5.1.1/node_modules/eslint-scope/lib/referencer.js:536:22)
at Referencer.Visitor.visit (project/node_modules/.pnpm/esrecurse@4.3.0/node_modules/esrecurse/esrecurse.js:104:34)
at Referencer.Visitor.visitChildren (project/node_modules/.pnpm/esrecurse@4.3.0/node_modules/esrecurse/esrecurse.js:83:38)
at Referencer.Program (project/node_modules/.pnpm/eslint-scope@5.1.1/node_modules/eslint-scope/lib/referencer.js:429:14)
The problem is that for module expressions Program nodes are generated which are already handled in eslint-scope .
The default visitor creates a global scope and expects no other scope to have been created but this then fails for the scope generated for module expressions.
As such the node must be handled explicitly in the referencer.
Either:
keep using a Program node but not adding a global scope for module expressions in the referencer
use a ModuleBlock node according to ESTree and add a visitor to the referencer
Additional context
I saw PR #15240 but this change also keeps creating Program nodes.
If this bug report is approved would you prefer creating a ModuleScope or a new kind of scope for module expressions?
The text was updated successfully, but these errors were encountered:
Hey @DMartens! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.
If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite.
Is there anything unclear with the bug report?
To summarize, the parser creates Program nodes for the bodies of the ModuleExpression which eslint-scope only expects once.
I successfully tried locally updating the Program visitor for eslint-scope by using a flag to check whether there was already a program node and if there was, nest an ModuleScope instead.
So no code changes are required for the parser if this is a concern.
As for the AST design, the @babel/eslint-parser's policy is to follow ESTree after eslint has implemented it, otherwise use Babel AST instead. So the analyze-scope.cjs should handle the nested Program node. We can create a ModuleScope like you said.
馃捇
How are you using Babel?
@babel/eslint-parser
Input code
Code:
Programmatic access:
Configuration file name
babel.config.js
Configuration
Current and expected behavior
Currently parsing any code module expression and analyzing the scope will lead to an error:
This is triggered here in eslint-scope
The expectation is that no error is thrown.
Environment
Possible solution
The problem is that for module expressions
Program
nodes are generated which are already handled ineslint-scope
.The default visitor creates a global scope and expects no other scope to have been created but this then fails for the scope generated for module expressions.
As such the node must be handled explicitly in the referencer.
Either:
Program
node but not adding a global scope for module expressions in the referencerModuleBlock
node according to ESTree and add a visitor to the referencerAdditional context
I saw PR #15240 but this change also keeps creating
Program
nodes.If this bug report is approved would you prefer creating a
ModuleScope
or a new kind of scope for module expressions?The text was updated successfully, but these errors were encountered: