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

Support omitting exception variable in bs files and convert exception var to an Expression #1305

Merged
merged 2 commits into from
Sep 26, 2024

Conversation

TwitchBronBron
Copy link
Member

@TwitchBronBron TwitchBronBron commented Sep 26, 2024

Our current CatchStatement stores the exception variable as a Token. This PR converts the CatchStatement.exceptionVariable property to an Expression, which supports VariableExpression and TypeCastExpression. This should more closely align with how TypeScript supports catch(e as <any type you want here>). This was a breaking change to the AST, so it needed to be done as part of v1.0.0

Also supports completely omitting the exception variable when you don't need to use it.

function init()
    try
        somethingDangerous()
    catch
        print "I live on the edge"
    end try
end function

transpiles to

function init()
    try
        somethingDangerous()
    catch e ' or __bsc_error if there's a local variable conflict
        print "I live on the edge"
    end try
end function

@TwitchBronBron TwitchBronBron merged commit 8f75b92 into release-1.0.0 Sep 26, 2024
6 checks passed
@TwitchBronBron TwitchBronBron deleted the catch-var-as-expression branch September 26, 2024 12:38
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.

2 participants