Skip to content

[Bug]: Scope bindings missing in AST for the variables which are introduced by babel-plugin-transform-destructuring #14438

@peey

Description

@peey

💻

  • Would you like to work on a fix?

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:?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    i: needs triageoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions