Content-Length: 287404 | pFad | http://redirect.github.com/babel/babel/issues/17282

6F Incorrect output when destructuring private property with duplicate properties and rest element · Issue #17282 · babel/babel · GitHub
Skip to content

Incorrect output when destructuring private property with duplicate properties and rest element #17282

Open
@JLHwung

Description

@JLHwung

💻

  • Would you like to work on a fix?

How are you using Babel?

Programmatic API (babel.transform, babel.parse)

Input code

REPL

class C {
  static #p = "#p";
  static a = "a";
  static {
    var { a, #p: p, a: x, ...r } = C;
    console.log(x);
  }
}

Configuration file name

No response

Configuration

{
  "plugins": ["@babel/plugin-proposal-destructuring-private"]
}

Current and expected behavior

Current: It logs undefined

Expected: It should log a

Environment

REPL

Possible solution

The output incorrectly excluded a when destructuring the patterns after the private property because a presents before #p:

const _excluded = ["a"];
// helper codes
class C {
  static #p = "#p";
  static a = "a";
  static {
    var {
        a
      } = C,
      p = C.#p,
      {
        a: x,
        ...r
      } = _objectWithoutProperties(C, _excluded);
    console.log(x);
  }
}

For simple all-literal cases, we can probably exclude a from the _excluded list. Otherwise if one of the keys are computed, such as

var { [a()]: a, #p: p, [a()]: x, ...r } = C;

we should further break down the pattern after #p ([a()]: x, ...r) into two declarators:

var _m, _m2;
    var {
        [_m = a()]: a
      } = C,
      p = C.#p,
      {
        [_m2 = a()]: x
      } = C,
      r = _objectWithoutProperties(C, [_m, _m2].map(_toPropertyKey));

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









      ApplySandwichStrip

      pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


      --- a PPN by Garber Painting Akron. With Image Size Reduction included!

      Fetched URL: http://redirect.github.com/babel/babel/issues/17282

      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy