Skip to content

Transpiled code from object rest within an array pattern in an assignment throws redeclaration error #17271

@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

let rest;

([{ ...rest }] = [{}])

for ([{ ...rest }] of [[{}]]);

Configuration file name

No response

Configuration

{
  "plugins": ["@babel/plugin-transform-object-rest-spread"]
}

Current and expected behavior

Current: The generated code throws redeclaration error because rest is defined as let and then redeclared with var

// helper code omitted
let rest;
[_ref] = [{}];
var rest = _extends({}, (_objectDestructuringEmpty(_ref), _ref));

Expected: This is valid JS, the transpiled code should not throw. rest should be defined and initialized as an empty object.

Environment

REPL

Possible solution

No response

Additional context

No response

Metadata

Metadata

Assignees

Labels

Spec: Object Rest/SpreadoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions