Skip to content
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]: @babel/traverse incorrect constantViolations with destructuring #16512

Open
1 task
j4k0xb opened this issue May 18, 2024 · 1 comment 路 May be fixed by #16522
Open
1 task

[Bug]: @babel/traverse incorrect constantViolations with destructuring #16512

j4k0xb opened this issue May 18, 2024 · 1 comment 路 May be fixed by #16522

Comments

@j4k0xb
Copy link

j4k0xb commented May 18, 2024

馃捇

  • 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);
  },
});

https://astexplorer.net/#/gist/a160da8edc997fcb75cf56061f0e0b79/72a54c5194bffab642627a4a2ddca828a2209f4f

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

@babel-bot
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants