Skip to content

[Bug]: Destructuring rest pattern generates undefined __rest variable #3331

Description

@nestarz

Reproduction link or steps

https://stackblitz.com/~/github.com/nestarz/stackblitz-rolldown-rest-error

Current Behavior

The generated code looks like:

({default: __default,...__rest} = __module);
build_default = __default !== void 0 ? __default : __rest;

where __rest is not defined, causing a ReferenceError.

Expected Behavior

The __rest[index] variable should be properly declared before being used in the destructuring assignment.

Environment

  • Rolldown version: 1.0.0-beta.1
  • Node.js version: 18.20.3

What is expected?

The __rest[index] variable should be properly declared before being used in the destructuring assignment.

What is actually happening?

When using object destructuring with rest pattern in the output code, the generated variable __rest[index] is not properly declared, leading to a ReferenceError.

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (4) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.20.3 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    rolldown: ^1.0.0-beta.1 => 1.0.0-beta.1

Any additional comments?

No response

Metadata

Metadata

Labels

Type

No type

Fields

Priority

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions