minifyminifilterterser

Using Terser, function names and vars not mangled, deadcode not removed


Using Terser I can not get the desired results.

I am trying to minify the testing code below and the function names do not get minified whatever I try. The variable names stay the same too, only within local functions that have parameters, they get changed. I have set toplevel to true and tried about every option I can think off. The deadcode in neverBeCalled does not go away either. Using Terser v4.3.4 and have no problem using another minifier if that would do the trick.

My config:

var options = {
    warnings: "verbose",
    keep_fnames: false,
    mangle: {
     toplevel: true,
   },
    compress: {
    passes: 20,
    dead_code: true,
    sequences: false,
    conditionals: false,
    drop_console: true,
},
    output: {
        ecma: 6,
        semicolons: false
    }

};

The testing source file:

init = function(){

test="testing";

bla = "blabla"

shameVar=903
}

update = function(){


test+="test"
test+="123"
x=10;
bla=bla+"x"
tester = myFuncWithLongName(23,24);
shameVar=shameVar-1;
}

myfuncWithLongName = function(eat,sleep){
resting=sleep+shameVar;
some = eat+resting;

return some;
}

neverBeCalled = function(){

thisdoesnot=0;
return thisdoesnot;

}

The result

init=function(){test="testing"
bla="blabla"
shameVar=903}
update=function(){test+="test"
test+="123"
x=10
bla+="x"
tester=myFuncWithLongName(23,24)
shameVar-=1}
myfuncWithLongName=function(t,e){resting=e+shameVar
some=t+resting
return some}
neverBeCalled=function(){thisdoesnot=0
return thisdoesnot}

Solution

  • This is not possible because without adding var the variables are global and Terser does not mangle them..