#1649·terser

[BUG] Bad output for Self-Defining Functions

Author: DKingAlphaCreated Nov 28, 2025Updated Sep 24, 2026

Input

javascript
// cond 1: strict mode
"use strict";

function ref_symbol(symbol) {
  console.log('ref_symbol', symbol);
}

// cond 2: function hoisting, used before declaration.
var a  = bad_function();
console.log(a);

// cond 3: no any other ref to bad_function in outer scope
// bad_function;

function bad_function() {
    // cond 4: pass as argument
    ref_symbol(bad_function);
    // cond 5: self-defining
    return (bad_function = function () {
       console.log("real bad_function");
    })();
}

Output

javascript
"use strict";var o=function o(){return function(o){console.log("ref_symbol",o)}(o),(o=function(){console.log("real bad_function")})()}();console.log(o)

Run

Expected:

bash
ref_symbol [Function: bad_function]
real bad_function
undefined

Got:

bash
ref_symbol [Function: o]
Uncaught TypeError: Assignment to constant variable.
    at o (REPL1:1:86)