-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
[Bug]: @babel/traverse incorrect constantViolations with destructuring #16512
Copy link
Copy link
Closed
Labels
outdatedA closed issue/PR that is archived due to age. Recommended to make a new issueA closed issue/PR that is archived due to age. Recommended to make a new issuepkg: traverse (scope)
Description
💻
- Would you like to work on a fix?
How are you using Babel?
Programmatic API (babel.transform, babel.parse)
Input code
const parser = require("@babel/parser");
const traverse = require("@babel/traverse").default;
const ast = parser.parse(`
function v() { }
const G2 = () => {
var a = 1;
var {
currentPoint: a,
centp: v,
} = {};
}
`);
traverse(ast, {
Program(path) {
const binding = path.scope.getBinding("v");
console.log(binding.constantViolations.length);
},
});Configuration file name
No response
Configuration
No response
Current and expected behavior
It currently detects the the VariableDeclarator with centp: v as a constantViolation of the global function v.
But v in G2 should be it's own binding.
Interestingly when the a variable or currentPoint: a is deleted, it logs 0 constantViolations for v
Environment
System:
OS: Linux 6.6 Manjaro Linux
Binaries:
Node: 20.10.0 - ~/.nvm/versions/node/v20.10.0/bin/node
Yarn: 4.1.1 - /usr/bin/yarn
npm: 10.2.3 - ~/.nvm/versions/node/v20.10.0/bin/npm
pnpm: 8.14.1 - /usr/bin/pnpm
npmPackages:
@babel/generator: ^7.24.5 => 7.24.5
@babel/parser: ^7.24.5 => 7.24.5
@babel/traverse: ^7.24.5 => 7.24.5
@babel/types: ^7.24.5 => 7.24.5
Possible solution
No response
Additional context
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
outdatedA closed issue/PR that is archived due to age. Recommended to make a new issueA closed issue/PR that is archived due to age. Recommended to make a new issuepkg: traverse (scope)