Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minimization invents variables, undefined #15

Open
bend-n opened this issue Dec 4, 2023 · 2 comments
Open

minimization invents variables, undefined #15

bend-n opened this issue Dec 4, 2023 · 2 comments

Comments

@bend-n
Copy link

bend-n commented Dec 4, 2023

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
@avispeng
Copy link

avispeng commented Nov 4, 2024

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

@lenscas
Copy link

lenscas commented Nov 26, 2024

Running into the same problem, turning

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

into

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants