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

Iife parse #343

Merged
merged 4 commits into from
Feb 27, 2021
Merged

Iife parse #343

merged 4 commits into from
Feb 27, 2021

Conversation

TwitchBronBron
Copy link
Member

Fixes a critical bug in BrsFile that would crash entire file parsing if the file contained an immediately-invoked-function-expression.
Also supports non-grouped IIFEs (gross, but technically valid syntax...so we should support it).

(expression.callee as any).callee
(expression.callee as any).callee ||
//filter out callees without a name (immediately-invoked function expressions)
!(expression.callee as any).name
Copy link
Member Author

@TwitchBronBron TwitchBronBron Feb 27, 2021

Choose a reason for hiding this comment

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

This was the fix for the crash. IIFEs don't have a name, but further down in this function we expected the expression.callee to have a name token. So now we guard against any callee without a name.

const func = this.functionDeclaration(true);
//if there's an open paren after this, this is an IIFE
if (this.check(TokenKind.LeftParen)) {
return this.finishCall(this.advance(), func);
Copy link
Member Author

Choose a reason for hiding this comment

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

Roku supports non-grouped IIFE. example:

print function()
    return true
end function()

This adds parser support for that pattern.

@TwitchBronBron TwitchBronBron merged commit 0c6b7f4 into master Feb 27, 2021
@TwitchBronBron TwitchBronBron deleted the iife-parse branch February 27, 2021 11: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.

2 participants