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
constparse=require('@babel/parser').parse;consttraverse=require('@babel/traverse').default;constgenerate=require('@babel/generator').default;constvisitors=require('@babel/traverse/lib/visitors');constast=parse('const a = 1; { const b = 2 };');constvisitor=visitors.merge([{Program(path){console.log(!!path.scope);},noScope: true,},{BlockStatement(path){console.log(!!path.scope);},noScope: true,},]);traverse(ast,visitor);// should log falsetraverse(ast,{});// some visitor that initializes scopetraverse(ast,visitor);// should log true
Configuration file name
No response
Configuration
No response
Current and expected behavior
Current behaviour (since #15702): noScope of merged visitors gets removed and causes the scope to be crawled anyways and overwrites the old scope.
Expected behaviour (v7.22.6): keep noScope in the merged visitor
I have to use multiple traversals, most use noScope: true to achieve better performance while still accessing the scope/references of a previous traversal.
Another reason is that the AST is sometimes temporarily in a broken state or I manually update references, and don't want the scope to be overwritten.
Hey @j4k0xb! 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.
@j4k0xb I have assigned this issue to you since you voiced your intent to work on this issue. Feel free to ask any questions if there are bumps when working on a fix.
馃捇
How are you using Babel?
Programmatic API (
babel.transform
,babel.parse
)Input code
Configuration file name
No response
Configuration
No response
Current and expected behavior
Current behaviour (since #15702):
noScope
of merged visitors gets removed and causes the scope to be crawled anyways and overwrites the old scope.Expected behaviour (v7.22.6): keep noScope in the merged visitor
I have to use multiple traversals, most use
noScope: true
to achieve better performance while still accessing the scope/references of a previous traversal.Another reason is that the AST is sometimes temporarily in a broken state or I manually update references, and don't want the scope to be overwritten.
Environment
System:
OS: Linux 5.15 Manjaro Linux
Binaries:
Node: 18.12.0 - ~/.nvm/versions/node/v18.12.0/bin/node
Yarn: 1.22.19 - /usr/bin/yarn
npm: 8.19.2 - ~/.nvm/versions/node/v18.12.0/bin/npm
npmPackages:
@babel/generator: ^7.22.7 => 7.22.7
@babel/helper-validator-identifier: ^7.22.5 => 7.22.5
@babel/parser: ^7.22.7 => 7.22.7
@babel/template: ^7.22.5 => 7.22.5
@babel/traverse: ^7.22.8 => 7.22.8
@babel/types: ^7.22.5 => 7.22.5
eslint: ^8.44.0 => 8.44.0
Possible solution
Set noScope of the merged visitor if all visitors have it.
Or v7.22.6 behaviour: if at least one has it?
Additional context
No response
The text was updated successfully, but these errors were encountered: