Rich-Harris / butternut

The fast, future-friendly minifier
https://butternut.now.sh
MIT License
1.17k stars 17 forks source link

Inlining function calls #105

Open Rich-Harris opened 7 years ago

Rich-Harris commented 7 years ago
// input
function foo () {
  function bar () {
    console.log(42);
  }
  bar();
}

// output
function foo(){function a(){console.log(42)}a()}

// better output
function foo(){console.log(42)}

I think this basically applies to any function that is only called once. The trick is to ensure that the scopes are merged for the purposes of mangling. Might get awkward when arguments are involved.