Skip to content

Root level for-loop's variables are transpiled to global variables #1631

Closed
@inklesspen1rus

Description

@inklesspen1rus

When for-loop is located at root level of the file, it's variables from initializer are global
But when I add any level (empty brackets or a function) they're being local

Example:

// Uncomment brackets to make `val` local
// {
    for (let val = 0; val < 2; ++val) print(val);
    print('For loop end')

    // Should be nil, but indeed it prints "2"
    print(val)
// }
--[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
do
    val = 0 -- here "local" keyword missing is
    while val < 2 do
        print(val)
        val = val + 1
    end
end
print("For loop end")
print(val)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions