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

Nuglify has issues with for of #414

Open
cuethenoise opened this issue Jan 15, 2025 · 1 comment
Open

Nuglify has issues with for of #414

cuethenoise opened this issue Jan 15, 2025 · 1 comment

Comments

@cuethenoise
Copy link

cuethenoise commented Jan 15, 2025

I am using the latest version of Nuglify.

The code

function Test(iterable) {
    for (let value of Object.values(iterable)) {       
        console.log(value);
    }
}
Test({
    foo: 10,
    bar: 12
});

Is being minified to:

function Test(n) {
    for (let n of Object.values(n))
        console.log(n)
}
Test({
    foo: 10,
    bar: 12
})

which results in the error:

Uncaught ReferenceError: Cannot access 'n' before initialization

Expected output would be:

function Test(n) {
    for (let o of Object.values(n))
        console.log(o)
}
Test({
    foo: 10,
    bar: 12
})

The latest version of uglify (3.17.4) in Debian produces the expected output.

My "workaround is to use var instead of let:

function Test(iterable) {
    for (var value of Object.values(iterable)) {       
        console.log(value);
    }
}
Test({
    foo: 10,
    bar: 12
});
@trullock
Copy link
Owner

yep, its let/const that cause this, var is the workaround.

PRs welcome

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

No branches or pull requests

2 participants