minify-js icon indicating copy to clipboard operation
minify-js copied to clipboard

minimization invents variables, undefined

Open bend-n opened this issue 2 years ago • 2 comments

minimize this code

for(let n=0;n<0;n++){Z((5+n)*8,5*8)}

with this code

fn main() {
    let mut o = vec![];
    minify_js::minify(
        &Session::new(),
        minify_js::TopLevelMode::Global,
        b"for(let n=0;n<0;n++){Z((5+n)*8,5*8)}",
        &mut o,
    )
    .unwrap();
    dbg!(String::from_utf8(o).unwrap());
}

and you get

for(let a=b;a<b;a++){Z((c+ a)*d,c*d)}

which fails with

Uncaught ReferenceError: b is not defined

bend-n avatar Dec 04 '23 23:12 bend-n

I am having the same issue. I use minify-js via minify-html. I have a function

function convertCtoF(val) {
  return Math.round((val * 1.8 + 32) * 10) / 10;
}

and it gets minified to var convertCtoF = (a => Math.round((a * 1.8 + 32) * b) / b); and I am having Uncaught ReferenceError: b is not defined

avispeng avatar Nov 04 '24 16:11 avispeng

Running into the same problem, turning

const getOpposite = (language) => language == "teal" ? "lua" : "teal"

into

const getOpposite = (a) => (a == b ? `lua` : b);

lenscas avatar Nov 26 '24 09:11 lenscas