#10817·rolldown

[Bug]: variables do not get tree-shaken in some cases

Author: nstepienCreated Sep 3, 2026Updated Sep 10, 2026

Reproduction link or steps

https://repl.rolldown.rs/#eNptkE1ugzAQha8ysiqRVMSQRVsJ1FWv4UUcMJElGEfGtImQ796x+Slp6401733jN+ORNawYmTVtW5sv5JXBRl+464OKrPjPSVlFhu6uxjoYoVaNRvURbfDQWNOBWPsEKwUKVLdIEyuHNt5rz24UCKDxOriCGjXW6kYxgqVBN4OLRoQAGmM7GTnVdzMCkGXQadTNvQBnB/VXTepKHQy29yRYngC/p7mYT9e8ZeG1/rVmr+gH6mXBhGdU9k6i6+lNgaEyreKtuewmdF/SE4oVYSLKWfFN1oM25c0fFZ0l8x2OeZ6Xwk4xLqw1OEX6aw7PMxXtH0SSm0g6yabvTOLpaZT+tBGrR3EzNE39SSMdec7zw1k5yV/emP8G4rO7tQ==

What is expected?

Unused variables/expressions should be removed from the resulting bundle.

//#region constants.ts
const second = 1e3;

//#endregion
//#region index.ts
console.log(second);

//#endregion

What is actually happening?

Rolldown removes unused variables, but leaves behind useless expressions.

//#region constants.ts
const second = 1e3;
60 * second;
const a = "aaaa";
`${a}`;
`${a}`;

//#endregion
//#region index.ts
console.log(second);

//#endregion

System Info

bash
System:
    OS: Windows 11 10.0.26200
    CPU: (32) x64 AMD Ryzen 9 9950X3D 16-Core Processor          
    Memory: 35.15 GB / 63.58 GB
  Binaries:
    Node: 26.8.1 - C:\Program Files\nodejs\node.EXE
    npm: 12.0.2 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 152.0.7977.76
    Edge: Chromium (152.0.4191.53)
    Firefox: 155.0 - C:\Program Files\Mozilla Firefox\firefox.exe

Any additional comments?

Additionally:

  • if I remove the variable declarations, but leave behind their expressions, the expressions will not be removed in the output either
    javascript
    export const second = 1000;
    60 * second;
    
    const a = 'aaaa';
    `${a}`;
    `${a}`;
  • removing one of the `${a}` DOES remove all the strings
    • input:
      javascript
      export const second = 1000;
      60 * second;
      
      const a = 'aaaa';
      `${a}`;
      // `${a}`;
    • output:
      javascript
      //#region constants.ts
      const second = 1e3;
      60 * second;
      
      //#endregion
      //#region index.ts
      console.log(second);
      
      //#endregion
  • enabling minify: true or minify: 'dce-only' does not help, surprisingly
  • with minify: true:
    • changing 1000 to 100 or 1e2 DOES remove the 60 * second expression
      • changing 1000 to 1e3 does not help
    • changing 'aaaa' to 'aaa' DOES remove all the strings
    • minify: 'dce-only' does not help with the above
    • input:
      javascript
      export const second = 100;
      60 * second;
      
      const a = 'aaa';
      `${a}`;
      `${a}`;
    • output:
      javascript
      console.log(100);