Skip to content

Support loop continue for 5.0, 5.1, and universal targets#1500

Merged
Perryvw merged 2 commits intoTypeScriptToLua:masterfrom
YoRyan:universal-continue
Oct 17, 2023
Merged

Support loop continue for 5.0, 5.1, and universal targets#1500
Perryvw merged 2 commits intoTypeScriptToLua:masterfrom
YoRyan:universal-continue

Conversation

@YoRyan
Copy link
Contributor

@YoRyan YoRyan commented Oct 16, 2023

Reinstates support for the continue statement using the original method proposed in #112, which is compatible with Lua versions that don't support goto.

Retains the goto method for 5.2+ since it is cleaner.

Transpiles from

for (let i = 1; i <= 100; i++) {
    if (i < 25) {
        continue;
    }
    print(i);
}

to

do
    i = 1
    while i <= 100 do
        do
            local __continue2
            repeat
                if i < 25 then
                    __continue2 = true
                    break
                end
                print(i)
                __continue2 = true
            until true
            if not __continue2 then
                break
            end
        end
        i = i + 1
    end
end

Copy link
Member

@lolleko lolleko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great PR, thanks.

[tstl.LuaTarget.Lua51]: builder => builder.expectDiagnosticsToMatchSnapshot([unsupportedForTarget.code]),
[tstl.LuaTarget.Universal]: expectContinueVariable,
[tstl.LuaTarget.Lua50]: expectContinueVariable,
[tstl.LuaTarget.Lua51]: expectContinueVariable,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect at least one test that asserts that this actually works. For example it might be a good idea to do a testEachVersion for the "for with continue" and "while with continue" tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I've modified all of the continue tests to test against all versions.

@Perryvw Perryvw merged commit e697c6e into TypeScriptToLua:master Oct 17, 2023
@YoRyan YoRyan deleted the universal-continue branch October 18, 2023 02:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants