💻
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
function f() { return {x: 1, y: 2}; }; const {x,y} = f();
The transformed source is
function f() {
return {
x: 1,
y: 2
};
}
;
const _f = f(),
x = _f.x,
y = _f.y;
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:?
|
convertVariableDeclaration( |
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
💻
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