Skip to content

[Bug]: Rolldown optimizes out scope variable assigned by eval #7846

@aquapi

Description

@aquapi

Reproduction link or steps

https://repl.rolldown.rs/#eNptTssKgzAQ/JVlL1oqtr0q9tRL/0EQ0aSkxI1oYiOSf28SsaeedufBzGzIsdhwUlL26kN5p4iLV/6eA0tY/FMy7LzA7KgmDT3jrZEatpoABI1GF5DkF0E9s96cZIFXRkchmoJNCmKPldpBdM8h5MwF6Mmw6AYYBAm+7lRgXE0OXYZH6jHuh/dJMV4yDQoquJYHauLHllamScC2upVNlZ6quz2r5BTVJg3X96DzPYsPk61ms0b3BTSOXiI=

What is expected?

{let o=0,_;eval(`let x=1;_=()=>x+o`),_()}

What is actually happening?

{let o=0,_;eval(`let x=1;_=()=>x+o`),(void 0)()}

System Info

System:
    OS: Linux 6.17 EndeavourOS
    CPU: (8) x64 Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
    Memory: 10.06 GB / 15.36 GB
    Container: Yes
    Shell: 5.3.3 - /bin/bash
  Binaries:
    Node: 24.8.0 - /run/user/1000/fnm_multishells/26925_1768214392161/bin/node
    Yarn: 1.22.22 - /run/user/1000/fnm_multishells/26925_1768214392161/bin/yarn
    npm: 11.6.0 - /run/user/1000/fnm_multishells/26925_1768214392161/bin/npm
    pnpm: 10.19.0 - /run/user/1000/fnm_multishells/26925_1768214392161/bin/pnpm
    bun: 1.3.5 - /home/reve/.bun/bin/bun
    Deno: 2.6.3 - /home/reve/.deno/bin/deno
  Browsers:
    Brave Browser: 143.1.85.118

Any additional comments?

This pattern seems to be a little faster than

new Function('o', 'var x=1;return ()=>x+o')(0)(o)

so I want to try it out for some compilation work.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions