Rich-Harris / butternut

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

Inline return values from functions #107

Open Rich-Harris opened 7 years ago

Rich-Harris commented 7 years ago

More advanced version of #104 and #105:

// input
function foo () {
  function bar () {
    return 42;
  }

  var answer = bar();
  console.log(answer);
}

// output
function foo(){function a(){return 42}var b=a();console.log(b)}

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

We can do this when a) the same inlining logic as in #104 applies, and b) the function body can be sequentialized.