Rich-Harris / butternut

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

Omit return statements that don't have an argument or return undefined #108

Open Rich-Harris opened 7 years ago

Rich-Harris commented 7 years ago

This already happens in simple cases:

// input
function foo () {
  console.log(1);
  return;
  console.log(2);
}

// output
function foo(){console.log(1)}

But it fails if there's a declaration after the return, even an unused one:

// input
function foo () {
  console.log(1);
  return;
  console.log(2);

  function x () {}
}

// output
function foo(){console.log(1);return}