#1698·terser

Mangle renames default parameter value to match destructured variable of same name, causing TDZ ReferenceError

Author: ther12kCreated Jun 22, 2026Updated Jun 22, 2026

Describe the bug

When mangling a function that has:

  1. A default parameter referencing an outer variable (using shorthand syntax or same-name property).
  2. A destructured variable declaration in the function body with the same name.

Terser incorrectly renames the default parameter value to match the mangled name of the local body variable, causing a runtime ReferenceError: Cannot access '...' before initialization (TDZ).

Minimal Reproduction

input.js:

javascript
const value = 'outer';

function example(ref = { value }) {
  const { value } = ref;
  console.log('local value =', value);
}

example();

Command:

bash
npx terser input.js --mangle --compress

Actual Output

javascript
const value="outer";function example(e={value:l}){const{value:l}=e;console.log("local value =",l)}example();

Running this throws:

ReferenceError: l is not defined
    at example (input.min.js:1:47)

Expected Output

Terser should not rename the default parameter value value to the body-local l since they refer to different variables in different scopes. It should keep it as value or rename it to whatever the outer variable is renamed to.

Expected minified:

javascript
const value="outer";function example(e={value:value}){const{value:l}=e;console.log("local value =",l)}example();

Versions

  • terser: ^5.36.0 (also reproduces on 5.48.0)
  • node: v20+ / v24+