Skip to content

Rollup fails with chained assignments #6007

@hsl0

Description

@hsl0

Rollup Version

v4.40.0 (my machine)
v4.44.2 (REPL)

Operating System (or Browser)

Windows 11 24H2

Node Version (if applicable)

v22.14.0

Link To Reproduction

https://rollupjs.org/repl/?version=4.44.2&shareable=JTdCJTIyZXhhbXBsZSUyMiUzQSUyMiUyMiUyQyUyMm1vZHVsZXMlMjIlM0ElNUIlN0IlMjJjb2RlJTIyJTNBJTIyaW1wb3J0JTIwJTdCZm9vJTJDJTIwYmF6JTdEJTIwZnJvbSUyMCcuJTJGbW9kdWxlXzEuanMnJTNCJTVDbmNvbnNvbGUubG9nKGZvbyUyQyUyMGJheiklM0IlMjIlMkMlMjJpc0VudHJ5JTIyJTNBdHJ1ZSUyQyUyMm5hbWUlMjIlM0ElMjJtYWluLmpzJTIyJTdEJTJDJTdCJTIyY29kZSUyMiUzQSUyMmNvbnN0JTIwJTdCZm9vJTJDJTIwYmFyJTdEJTIwJTNEJTIwYmF6JTIwJTNEJTIwJTdCZm9vJTNBJTIwMSUyQyUyMGJhciUzQSUyMDIlN0QlM0IlNUNuZXhwb3J0JTIwJTdCZm9vJTJDJTIwYmFyJTJDJTIwYmF6JTdEJTNCJTIyJTJDJTIyaXNFbnRyeSUyMiUzQWZhbHNlJTJDJTIybmFtZSUyMiUzQSUyMm1vZHVsZV8xLmpzJTIyJTdEJTVEJTJDJTIyb3B0aW9ucyUyMiUzQSU3QiUyMm91dHB1dCUyMiUzQSU3QiUyMmZvcm1hdCUyMiUzQSUyMmVzJTIyJTdEJTdEJTdE

Expected Behaviour

Rollup should correctly parse and bundle the module, handling chained assignments and destructuring in export statements without error.

The expected bundle result would be:

const {foo} = baz = {foo: 1, bar: 2};

console.log(foo, baz);

When the code is refactored to avoid chained assignments and use separate constant definitions, the equivalent code bundles successfully without error: https://rollupjs.org/repl/?version=4.44.2&shareable=JTdCJTIyZXhhbXBsZSUyMiUzQSUyMiUyMiUyQyUyMm1vZHVsZXMlMjIlM0ElNUIlN0IlMjJjb2RlJTIyJTNBJTIyaW1wb3J0JTIwJTdCZm9vJTJDJTIwYmF6JTdEJTIwZnJvbSUyMCcuJTJGbW9kdWxlXzEuanMnJTNCJTVDbmNvbnNvbGUubG9nKGZvbyUyQyUyMGJheiklM0IlMjIlMkMlMjJpc0VudHJ5JTIyJTNBdHJ1ZSUyQyUyMm5hbWUlMjIlM0ElMjJtYWluLmpzJTIyJTdEJTJDJTdCJTIyY29kZSUyMiUzQSUyMmNvbnN0JTIwYmF6JTIwJTNEJTIwJTdCZm9vJTNBJTIwMSUyQyUyMGJhciUzQSUyMDIlN0QlM0IlNUNuY29uc3QlMjAlN0Jmb28lMkMlMjBiYXIlN0QlMjAlM0QlMjBiYXolM0IlNUNuZXhwb3J0JTIwJTdCZm9vJTJDJTIwYmFyJTJDJTIwYmF6JTdEJTNCJTIyJTJDJTIyaXNFbnRyeSUyMiUzQWZhbHNlJTJDJTIybmFtZSUyMiUzQSUyMm1vZHVsZV8xLmpzJTIyJTdEJTVEJTJDJTIyb3B0aW9ucyUyMiUzQSU3QiU3RCU3RA==

Actual Behaviour

It throws an error

[!] TypeError: Cannot read properties of null (reading 'module')
    at setAlternativeExporterIfCyclic (C:\Users\***\AppData\Roaming\fnm\node-versions\v22.14.0\installation\node_modules\rollup\dist\shared\rollup.js:19131:18)
    at Module.getVariableForExportName (C:\Users\***\AppData\Roaming\fnm\node-versions\v22.14.0\installation\node_modules\rollup\dist\shared\rollup.js:18522:17)
    at getVariableForExportNameRecursive (C:\Users\***\AppData\Roaming\fnm\node-versions\v22.14.0\installation\node_modules\rollup\dist\shared\rollup.js:18156:19)
    at Module.traceVariable (C:\Users\***\AppData\Roaming\fnm\node-versions\v22.14.0\installation\node_modules\rollup\dist\shared\rollup.js:18784:35) 
    at ModuleScope.findVariable (C:\Users\***\AppData\Roaming\fnm\node-versions\v22.14.0\installation\node_modules\rollup\dist\shared\rollup.js:16449:39)
    at Identifier.bind (C:\Users\***\AppData\Roaming\fnm\node-versions\v22.14.0\installation\node_modules\rollup\dist\shared\rollup.js:9125:40)       
    at CallExpression.bind (C:\Users\***\AppData\Roaming\fnm\node-versions\v22.14.0\installation\node_modules\rollup\dist\shared\rollup.js:6548:28)   
    at CallExpression.bind (C:\Users\***\AppData\Roaming\fnm\node-versions\v22.14.0\installation\node_modules\rollup\dist\shared\rollup.js:13529:15)  
    at ExpressionStatement.bind (C:\Users\***\AppData\Roaming\fnm\node-versions\v22.14.0\installation\node_modules\rollup\dist\shared\rollup.js:6552:23)
    at Program.bind (C:\Users\***\AppData\Roaming\fnm\node-versions\v22.14.0\installation\node_modules\rollup\dist\shared\rollup.js:6548:28

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions