Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds async/await support to brighterscript.
Leverages the @rokucommunity/promises library to support syncronous-looking flows into promise-drive async flows. For example:
Would transpile into something like:
There are many complex use cases that we won't be covering in this first iteration (like if statements, loops, etc). For now, we will handle the simple case of top-level function statements and try-catch.
Tasks:
1. Add lexer and parser support for
async
andawait
. Both should be fully allowed as local variables, function names, etc. But when used in the context of an async function, or an await statement, it will result in new AST.FunctionStatement
calledasyncToken
. This is how we will determine if the function is async or not.AwaitedExpression
that are not at the root of a function body. In the future we will add more support for nested expressions, but that gets complicated quick...2. Integrate the @rokucommunity/promises library into brighterscript in a similar fashion to bslib. The promises library should only be included IF async/await is used. Also, if the project already has an instance of @rokucommunity/promises, then bsc shouldn't include another copy and should instead leverage that one.
3. Write the transpiler logic for async/await.