Uglifyjs: Bug: switch default doesnt need to be last

Created on 25 Mar 2017  路  3Comments  路  Source: mishoo/UglifyJS

  • Bug report or feature request?
    Bug. Fuzzer found it. But okay, I nudged it there.

  • uglify-js version (uglifyjs -V)
    uglify-js 2.8.16 (git master)

So this is a language oddity; the default clause in JS switch statements doesn't need to be last. The fall-through cases are even more of a brainf* in this context... ;)

switch (undefined) {
  default:
    console.log('FAIL');
    break;
  case undefined:
    console.log('PASS');
    break;
}
$ bin/uglifyjs s.js -c
WARN: Dropping unreachable code [s.js:4,4]
WARN: Dropping unreachable code [s.js:5,2]
console.log("FAIL");



md5-a97ef0d5cc2535e26d5da5a59e1452b2



$ node s.js && bin/uglifyjs s.js -c | node
PASS
WARN: Dropping unreachable code [s.js:4,4]
WARN: Dropping unreachable code [s.js:5,2]
FAIL
bug

All 3 comments

(Away for most of the rest of the day. Maybe you can enjoy the Saturday better this way... ;) )

Pretty sure this case is the same bug:

function f() {
  function g() {
    switch (0) {
      default:
      case console.log('PASS'):
    }
  }
  g();
}
f();

It's a different issue, but I might as well fix it under the same PR.

Edit: scrap that, it's #1678

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Jimbly picture Jimbly  路  4Comments

PinkyJie picture PinkyJie  路  3Comments

GrosSacASac picture GrosSacASac  路  3Comments

uiteoi picture uiteoi  路  5Comments

alexlamsl picture alexlamsl  路  4Comments