Skip to content

es/minifier: hoist_vars does not work for for-loop initializers #10395

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

Open
Le0Developer opened this issue Apr 20, 2025 · 0 comments
Open

es/minifier: hoist_vars does not work for for-loop initializers #10395

Le0Developer opened this issue Apr 20, 2025 · 0 comments
Assignees
Milestone

Comments

@Le0Developer
Copy link

Describe the feature

In this example, var nothoisted does not get hoisted to the top of the function, resulting in an unnecessary var declaration in the for-loop initializer.

function main() {
    var hoisted = "323232"
    console.log(hoisted, hoisted)

    for(var nothoisted = "123434";;) {
        console.log(nothoisted, nothoisted)
    }

    var hoisted2 = "123434"
    for(;;) {
        console.log(hoisted2, hoisted2)
    }
}

export { main }

Output:

function main() {
    var hoisted2, hoisted = "323232";
    console.log(hoisted, hoisted);
    for(var nothoisted = "123434";;)console.log(nothoisted, nothoisted);
    for(hoisted2 = "123434";;)console.log(hoisted2, hoisted2);
}
export { main };

Babel plugin or link to the feature description

https://play.swc.rs/?version=1.11.21&code=H4sIAAAAAAAAA0srzUsuyczPU8hNzMzT0FSo5lIAgrLEIoWM%2FMziktQUBVsFJWMjEFQCSyXn5xXn56Tq5eSna0CV6MDUanKBlaTlF2mATMjLL0EyxNDI2MTYRMnaGmYJumkI5TpIWjXBamu50N1lhGQm3FbchsN0wd1qBDMYaDRXakVBflGJQjU4FBRqAVFpJvgVAQAA&config=H4sIAAAAAAAAA32UyY7bMAxA7%2F2KwOe5tod%2BQG%2FzDYJiUQ6nsmiIVCbGIP9eesnSCe1LEPNxE7evH4dD88Ft8%2FvwpX%2F1Y%2FCFody%2FVcJjFn9RSSPjANwWHKSZ4fVtsRFfOpBJA%2FhnswoTEYPKok8Mq6zHjHF8dt5SPxRgfpKpVP3VHrLw%2F%2FYrK%2FQ5ASn1WX4kSuDzDnGeHWaBDorluKWU%2FMDgzr4YXqZMfUEmK8QEq0BwQ6HB5DmgIGWN%2BUoD%2BOBaCmAgLNAKnsEy01hqllmfZ7xnxgGOtevmhn6zhrNP1YsREy5zSzRbw%2BuJkMXFmq0SLnCjBgu0i4vRFZBa8iv6IMwbVn8BtADJM2ffg5XQrBF1nLas464l5qgTK6PBdbytR2botKYOMRqFnQoDRdBqZoFQW5gK21rprHitw3fKGMBBjDoqhmv%2BRGlPVtBpoSkaQNvrozVUC3D3Jdzg0z7s4D%2F6SrHna9XovZy2KY%2F9kdJOgB7kRGFHQVshtI2LHonLsM1rDqCjAcFUqTyD1xug8y%2Fk0nwrX2ZDt0M9ui7R8XElVoXrTbPpfe4e6%2F44w%2FNP01OoM12v%2BdTg5S7%2Fah5Ktyt8z7xBfr9ZLnld%2FwEcwLyUGgYAAA%3D%3D

Additional context

No response

@Austaras Austaras self-assigned this Apr 20, 2025
@kdy1 kdy1 added this to the Planned milestone May 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants