You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As the title already says, when the compression is enabled, even some used variables get dropped. Sometimes it is also happens for imported modules when static blocks come into picture.
Version (complete output of terser -V or specific git commit)
Terser REPL
Complete CLI command or minify() options used
NA
terser input
consttestVarOne='Hello this is test var one';consttestVarTwo=(/* unused pure expression or super */null&&(`${testVarOne}Hello this is test var two`));consttestObj={one: `${testVarOne}`};let_initClass;functionfn($class){return[classextends$class{},function(){}];}let_MyElement;classMyElement{static{[_MyElement,_initClass]=fn(this);}prop=testObj.one;static{_initClass();}}
consttestVarOne='Please preserve this';constusedOnce=testVarOneconstusedTwice=testVarOneclassMyElement{static{// class refers to itself AND has side-effects.sideEffect(this);}notDeletedReference=usedTwice;}
The class MyElementlooks like it will be dropped because it's unused. But it's not dropped because sideEffect(this) is a use of the class. Using sideEffect(MyElement) would fix the issue, which tells me the problem probably showed up when Terser started to recognize a class this as a reference to it.
Bug report
As the title already says, when the compression is enabled, even some used variables get dropped. Sometimes it is also happens for imported modules when static blocks come into picture.
Version (complete output of
terser -V
or specific git commit)Terser REPL
Complete CLI command or
minify()
options usedNA
terser
inputterser
output or errorExpected result
The text was updated successfully, but these errors were encountered: