Visitar URL original
[Bug]: Tree-shaking drops `new ArrayBuffer(-1)` and malformed `decodeURIComponent` / `encodeURI` calls that throw · Issue #11550 · rolldown/rolldown · GitHub
Skip to content

[Bug]: Tree-shaking drops new ArrayBuffer(-1) and malformed decodeURIComponent / encodeURI calls that throw #11550

Open

Description

@trackoor

Reproduction link or steps

https://gist.github.com/trackoor/04c59457a8f7df159782d5d8c8d69810

// m.js
try { const x = new ArrayBuffer(-1); console.log('no throw'); } catch (e) { console.log(e.constructor.name); }
try { const x = decodeURIComponent('%'); console.log('no throw'); } catch (e) { console.log(e.constructor.name); }
try { const x = encodeURI('\uD800'); console.log('no throw'); } catch (e) { console.log(e.constructor.name); }

// main.js
import './m.js';

Run:

npx rolldown main.js -o out.mjs && node out.mjs

What is expected?

Tree-shaking preserves the throwing new ArrayBuffer(-1), decodeURIComponent('%'), and encodeURI('\uD800') calls (as Node, Rollup, esbuild, and webpack do, and as Rolldown does for new Int8Array(-1)), printing:

RangeError
URIError
URIError

What is actually happening?

Rolldown strips all three unused const x = ... declarations and prints:

no throw
no throw
no throw

System Info

  System:
    OS: macOS 26.3
    CPU: (14) arm64 Apple M3 Max
    Memory: 861.34 MB / 36.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 24.14.1 - /Users/hanzhi/.nvm/versions/node/v24.14.1/bin/node
    Yarn: 1.22.22 - /opt/homebrew/bin/yarn
    npm: 11.11.0 - /Users/hanzhi/.nvm/versions/node/v24.14.1/bin/npm
    pnpm: 11.24.0 - /opt/homebrew/bin/pnpm
  Browsers:
    Chrome: 156.0.8078.80
    Safari: 26.3
  npmPackages:
    rolldown: ^1.3.0 => 1.3.0

Any additional comments?

new ArrayBuffer(-1) throws RangeError on negative indices, and decodeURIComponent('%') / encodeURI('\uD800') throw URIError on malformed percent-escapes or unpaired surrogates, but side-effect detection only checks new ArrayBuffer(arg) for Symbol/BigInt arguments and treats decodeURI/decodeURIComponent/encodeURI/encodeURIComponent as unconditionally pure regardless of literal arguments.

Credit: https://ucsbplse.github.io/

Activity

  1. changed the title [-]Tree-shaking drops `new ArrayBuffer(-1)` and malformed `decodeURIComponent` / `encodeURI` calls that throw[/-] [+][Bug]: Tree-shaking drops `new ArrayBuffer(-1)` and malformed `decodeURIComponent` / `encodeURI` calls that throw[/+] on Nov 7, 2026
  2. IWANABETHATGUY commented on Nov 7, 2026

    @IWANABETHATGUY
    Member

    https://playground.oxc.rs/?options=%7B%22run%22%3A%7B%22lint%22%3Atrue%2C%22formatter%22%3Afalse%2C%22transform%22%3Afalse%2C%22isolatedDeclarations%22%3Afalse%2C%22whitespace%22%3Afalse%2C%22mangle%22%3Afalse%2C%22mangleProps%22%3Afalse%2C%22compress%22%3Atrue%2C%22scope%22%3Atrue%2C%22symbol%22%3Atrue%2C%22cfg%22%3Afalse%7D%2C%22parser%22%3A%7B%22extension%22%3A%22tsx%22%2C%22allowReturnOutsideFunction%22%3Atrue%2C%22preserveParens%22%3Atrue%2C%22allowV8Intrinsics%22%3Atrue%2C%22semanticErrors%22%3Atrue%7D%2C%22linter%22%3A%7B%7D%2C%22formatter%22%3A%7B%22useTabs%22%3Afalse%2C%22tabWidth%22%3A2%2C%22endOfLine%22%3A%22lf%22%2C%22printWidth%22%3A80%2C%22singleQuote%22%3Afalse%2C%22jsxSingleQuote%22%3Afalse%2C%22quoteProps%22%3A%22as-needed%22%2C%22trailingComma%22%3A%22all%22%2C%22semi%22%3Atrue%2C%22arrowParens%22%3A%22always%22%2C%22bracketSpacing%22%3Atrue%2C%22bracketSameLine%22%3Afalse%2C%22objectWrap%22%3A%22preserve%22%2C%22singleAttributePerLine%22%3Afalse%7D%2C%22transformer%22%3A%7B%22target%22%3A%22es2015%22%2C%22useDefineForClassFields%22%3Atrue%2C%22experimentalDecorators%22%3Atrue%2C%22emitDecoratorMetadata%22%3Atrue%2C%22optimizeEnums%22%3Atrue%2C%22optimizeConstEnums%22%3Atrue%7D%2C%22isolatedDeclarations%22%3A%7B%22stripInternal%22%3Afalse%7D%2C%22codegen%22%3A%7B%22normal%22%3Atrue%2C%22jsdoc%22%3Atrue%2C%22annotation%22%3Atrue%2C%22legal%22%3Atrue%7D%2C%22compress%22%3A%7B%7D%2C%22mangle%22%3A%7B%22topLevel%22%3Atrue%2C%22keepNames%22%3Afalse%7D%2C%22mangleProps%22%3A%7B%22include%22%3A%22_%24%22%2C%22reserved%22%3A%5B%5D%2C%22quoted%22%3Afalse%2C%22debug%22%3Afalse%7D%2C%22controlFlow%22%3A%7B%22verbose%22%3Afalse%7D%2C%22inject%22%3A%7B%22inject%22%3A%7B%7D%7D%2C%22define%22%3A%7B%22define%22%3A%7B%7D%7D%7D&code=%2F%2F+m.js%0Atry+%7B+const+x+%3D+new+ArrayBuffer%28-1%29%3B+console.log%28%27no+throw%27%29%3B+%7D+catch+%28e%29+%7B+console.log%28e.constructor.name%29%3B+%7D%0Atry+%7B+const+x+%3D+decodeURIComponent%28%27%25%27%29%3B+console.log%28%27no+throw%27%29%3B+%7D+catch+%28e%29+%7B+console.log%28e.constructor.name%29%3B+%7D%0Atry+%7B+const+x+%3D+encodeURI%28%27%5CuD800%27%29%3B+console.log%28%27no+throw%27%29%3B+%7D+catch+%28e%29+%7B+console.log%28e.constructor.name%29%3B+%7D%0A%0A%2F%2F+main.js%0Aimport+%27.%2Fm.js%27%3B

  3. trackoor commented on Nov 7, 2026

    @trackoor
    Author

    Thanks, this comes from the oxc minifier, so I reported it there: oxc-project/oxc#28974

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions