coderaiser / minify

Minifier of js, css, html and img
https://coderaiser.github.io/minify
MIT License
229 stars 29 forks source link

Wrong execution order #111

Closed TheIndra55 closed 1 year ago

TheIndra55 commented 1 year ago

We're running into an issue where minify executes a function before it should.

minify --version
v10.3.0

I've made a small repro from our code

async function onChange(event) {
    const element = event.target

    const type = element.dataset.inputType ?? "email"
    const target = element.dataset.resultElement

    let domain = element.value

    if (type == "email") {
        domain = domain.split("@")[1]
    }

    const result = await checkDomain(domain)

    const targetElement = document.getElementById(target)
    targetElement.innerHTML = `Result: ${result.data}`
}

async function checkDomain(domain) {
    return await fetch("/domain/" + domain).then(response => response.json())
}

document.querySelector("input").addEventListener("change", onChange)

This produces the following minified code:

async function a(a) {
    var b = a.target,
        c = b.dataset.inputType ?? "email",
        e = b.value,
        f = await b(e),
        g = document.getElementById(b.dataset.resultElement);
    c == "email" && (e = e.split("@")[1]);
    g.innerHTML = `Result: ${f.data}`
}

The checkDomain function is called before the string operation is done on domain.

coderaiser commented 1 year ago

Just fixed 🎉 , please re-install Minify, is it works for you?

TheIndra55 commented 1 year ago

I've done npm remove minify -g and then installed it again, i've also tried npm update -g but it still seems to happen.

Is there a way to make sure I'm on the latest version of the dependencies?

coderaiser commented 1 year ago

Just made fix, please try again. Is it works for you?

TheIndra55 commented 1 year ago

This issue has been resolved in the recent version.

Thanks for the fix!