Skip to content

Transpiled code from object rest within an array pattern in a for declaration throws "ref is not defined" error #17272

@JLHwung

Description

@JLHwung

💻

  • Would you like to work on a fix?

How are you using Babel?

babel-loader (webpack)

Input code

REPL

for (const [{ ...rest }] = [{}]; false; );

Configuration file name

No response

Configuration

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

Current and expected behavior

Current: The transpiled code throws "_ref is not defined" error because the rest definition is moved out of the for loop.

// helper code omitted

for (const [_ref] = [{}]; false;);
var rest = _extends({}, (_objectDestructuringEmpty(_ref), _ref));

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

Environment

REPL

Possible solution

No response

Additional context

This issue may be related to #17271, though the error message is different.

Metadata

Metadata

Assignees

No one assigned

    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