Skip to content

[Bug]: path.remove() removes var binding by mistake #14429

@liuxingbaoyu

Description

@liuxingbaoyu

💻

  • Would you like to work on a fix?

How are you using Babel?

Programmatic API (babel.transform, babel.parse)

Input code

var traverse = require("@babel/traverse").default;
var parser = require("@babel/parser");

var ast = parser.parse('var a=1;a=2;');
traverse(ast, {
  AssignmentExpression(path) {
    console.log(path.scope.getBinding("a"));
    path.remove();
    console.log(path.scope.getBinding("a"));
  }
});

Configuration file name

No response

Configuration

No response

Current and expected behavior

current

Binding {identifier: Node, scope: Scope, path: NodePath, kind: 'var', constantViolations: Array(1), …}
undefined

expected

Binding {identifier: Node, scope: Scope, path: NodePath, kind: 'var', constantViolations: Array(1), …}
Binding {identifier: Node, scope: Scope, path: NodePath, kind: 'var', constantViolations: Array(1), …}

Environment

  System:
    OS: Windows 10 10.0.22000
  Binaries:
    Node: 16.4.0 - C:\Program Files\nodejs\node.EXE
    npm: 7.18.1 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    @babel/core: ^7.10.4 => 7.10.4
    @babel/generator: ^7.17.3 => 7.17.9
    @babel/parser: ^7.17.3 => 7.17.9
    @babel/template: ^7.10.4 => 7.16.7
    @babel/traverse: ^7.17.9 => 7.17.9
    @babel/types: ^7.17.0 => 7.17.0

Possible solution

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions