[BUG] Functions are inlined incorrectly if variable name matches a catch-block exception name
Author: bayotopCreated Jul 23, 2026Updated Jul 23, 2026
Default configuration (module: false), version 5.49.0.
POC:
function foo(i, j) {
const a = function(i, j) {
return i(j);
};
const b = function(i, j) {
return i === j
};
let r;
try {
r = a(i, j)
} catch (b) {
// Naming the caught error 'b' results in terser messing up minification,
// and replacing 'b' with function(){}(_, 4) in the return statement below.
throw b;
}
return b(r, 4);
}
foo((i) => { return 2*i }, 2)Actual result:
function foo(n,t){const o=function(n,t){return n===t};let r;try{r=function(n,t){return n(t)}(n,t)}catch(o){throw o}return function(){}(r,4)}foo(n=>2*n,2);Expected result:
function foo(t,n){let o;try{o=function(t,n){return t(n)}(t,n)}catch(t){throw t}return function(t,n){return t===n}(o,4)}foo(t=>2*t,2);In the current state, calling foo will always return undefined. I did not look for the actual root cause, however the expected minified code is produced when the function name (b) is different than the exception caught in the catch-block.
Source: terser/terser