Skip to content

Name collision caused by let in loop initializer #997

@lorenzodallavecchia

Description

@lorenzodallavecchia

Bug report

Version

terser 5.7.0

Complete CLI command

terser --compress -- input.js

terser input

function main(e) {
    console.log(e.length);
    let other = "12";
    for (let e; e = 0;) {
        console.log(e);
    }
}
main("foo");

terser output

function main(e){console.log(e.length);let e;for(;e=0;)console.log(e)}main("foo");

When executed, the code throws SyntaxError: Identifier 'e' has already been declared.
The let declaration hoisted from inside the for loop causes a name conflict with the function parameter.

Expected result

I would expect the let declaration to stay inside the loop, even if there is a previous let declaration outside of the loop

Other notes

I can work around the issue by disabling join_vars compress option.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions