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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Scope bindings missing in AST for the variables which are introduced by babel-plugin-transform-destructuring
#14438
Comments
Hey @peey! 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. |
This problem may be difficult to fix. |
Hi @liuxingbaoyu . I agree that's a good alternative perhaps. But I think if this can be fixed it could be useful to downstream plugins which need scope info (e.g. if some plugin runs after de-structuring, for correct operation it definitely needs correct scope info right?) I've tried to fix it and made some progress. Please look at the linked PR (very small change - 2 lines in source, ~60 lines in test) in case you have any insights you can share which could help improve it. |
1. Update tests: some were spurious failures 2. Address failing tests: introduce scope crawling in for statement cases
Yes, I think that makes sense too. However I prefer to provide options to isolate plugins, which is clearly an issue in many plugins. |
What do you mean by isolating plugins in context of this issue? If you mean they should have clear boundaries and interfaces then I agree. I think this would be a step towards it. Instead of having to worry about "I might have scope bindings if I ran before plugin X but not before plugin Y" this can be a first step towards providing the guarantee that "Each plugin will always receive a proper AST with full information as input, and must produce a proper AST as output". Currently Thankfully I was able to fix this issue in the linked PR for |
馃捇
How are you using Babel?
Programmatic API (
babel.transform
,babel.parse
)Input code
https://github.com/peey/babel-missing-ast-scope-bindings-repro
Configuration file name
No response
Configuration
No response
Current and expected behavior
Current Behavior
No scope bindings in the AST for variables introduced by
@babel/plugin-transform-destructuring
.E.g. in the example
The transformed source is
Each variable has an associated scope binding in the AST, but the variable introduced by the transform (
_f
) does not.Expected Behavior
Scope bindings expected to be present
Environment
Binaries:
Node: 16.13.0 - ~/.nvm/versions/node/v16.13.0/bin/node
Yarn: 1.22.17 - ~/.nvm/versions/node/v16.13.0/bin/yarn
npm: 8.1.0 - ~/.nvm/versions/node/v16.13.0/bin/npm
npmPackages:
@babel/core: ^7.17.9 => 7.17.9
@babel/parser: ^7.17.9 => 7.17.9
@babel/plugin-transform-destructuring: ^7.17.7 => 7.17.7
@babel/traverse: ^7.17.9 => 7.17.9
@babel/types: ^7.17.0 => 7.17.0
Possible solution
Perhaps the related piece of source code is the following:?
babel/packages/babel-plugin-transform-destructuring/src/index.ts
Line 161 in f854373
I was expecting to find templates which introduce the variable, but it seems like the resulting AST is constructed in another way for this transform so I'm not sure.
Additional context
No response
The text was updated successfully, but these errors were encountered: