-
Notifications
You must be signed in to change notification settings - Fork 38
Done, but do not merge yet: Async/Await syntax. #600
Commits on Jul 18, 2022
-
Implement parsing of
await
expressions.operand-expr += `await` unary-expr
Maxim committedJul 18, 2022 Configuration menu - View commit details
-
Copy full SHA for 21c01e6 - Browse repository at this point
Copy the full SHA 21c01e6View commit details -
Implement parsing of
async
expressionsoperand-expr += `async` es6-arrow-expression
Maxim committedJul 18, 2022 Configuration menu - View commit details
-
Copy full SHA for 5995738 - Browse repository at this point
Copy the full SHA 5995738View commit details -
Make "await". and "async" non-keywords.
Existing code using async/await as identifiers in e.g. record field names will keep working.
Maxim committedJul 18, 2022 Configuration menu - View commit details
-
Copy full SHA for 454d5b6 - Browse repository at this point
Copy the full SHA 454d5b6View commit details -
Implement printer support for async arrow expressions
Maxim committedJul 18, 2022 Configuration menu - View commit details
-
Copy full SHA for 686fa53 - Browse repository at this point
Copy the full SHA 686fa53View commit details -
Implement printer support for await expressions
Maxim committedJul 18, 2022 Configuration menu - View commit details
-
Copy full SHA for 5c91bc4 - Browse repository at this point
Copy the full SHA 5c91bc4View commit details -
Implement printing of parens (precedence) for await expressions
Maxim committedJul 18, 2022 Configuration menu - View commit details
-
Copy full SHA for 03db389 - Browse repository at this point
Copy the full SHA 03db389View commit details -
Make sure the "async" identifier can be used without being interprete…
…d as async arrow function
Maxim committedJul 18, 2022 Configuration menu - View commit details
-
Copy full SHA for 9e711a4 - Browse repository at this point
Copy the full SHA 9e711a4View commit details -
Reasoning: In JavaScript `await` is a keyword *only* inside async functions. ```javascript let await = 1 // OK ✅ async function wait() { let await = 1 // NOT OK ❌ } ``` The plot twist is that the newer browsers (chrome or node) support top-level await. (By implicitly wrapping everything in an async function?) ```javascript let await = 1 // NOT OK, with top level await ❌ ``` This makes me think: * We can replicate JavaScript parser; inside async function expressions, use of `await` as identifier will result into a syntax error - Downside: this feels like a responsibility for another part of the compiler, not the parser? This is already implemented in cristianoc/rescript-compiler-experiments#1, so we would also be doing double work. - Other downside: if we ever allow top-level await, then we just implemented the above for nothing. * Allow `await` as a "non-keyword" everywhere with some "tricks". ```javascript let await = 1 let x = await // Ok, now it gets tricky. Does this start an "await"-expression? = await fetch(url) // could be this = await() // could be this = await await() // or even this = await // or we might just be assigning the identifier `await` to `x` ``` Seems like we can infer the following rules for an `await expression`: - space after `await` - next token is on the same line as `await` - next token indicates the start of a unary expression But this "breaks down" in the case of ```javascript let x = await - 1 // could be a binary expression: "identifier" MINUS "1" // could also be an await expression with a unary expression: `await` `(-1)` ``` These whitespace sensitive rules kinda feel super arbitrary. Which makes me think that introducing `await` as a keyword is an ok compromise.
Maxim committedJul 18, 2022 Configuration menu - View commit details
-
Copy full SHA for d0b7cb1 - Browse repository at this point
Copy the full SHA d0b7cb1View commit details -
Remove
assert false
branch from async arrow expression parsingMaxim committedJul 18, 2022 Configuration menu - View commit details
-
Copy full SHA for 0283e8d - Browse repository at this point
Copy the full SHA 0283e8dView commit details -
Make
processFunctionAttributes
return a record instead of tupleMaxim committedJul 18, 2022 Configuration menu - View commit details
-
Copy full SHA for dc85c21 - Browse repository at this point
Copy the full SHA dc85c21View commit details -
Configuration menu - View commit details
-
Copy full SHA for 66defd5 - Browse repository at this point
Copy the full SHA 66defd5View commit details -
Rename @await/@async to @res.await/@res.async
Maxim committedJul 18, 2022 Configuration menu - View commit details
-
Copy full SHA for ff69dfa - Browse repository at this point
Copy the full SHA ff69dfaView commit details -
Alphabetically sort variant cases in
isBlockExprStart
Maxim committedJul 18, 2022 Configuration menu - View commit details
-
Copy full SHA for 3d5af74 - Browse repository at this point
Copy the full SHA 3d5af74View commit details -
Sort variant cases
isExprStart
alphabeticallyMaxim committedJul 18, 2022 Configuration menu - View commit details
-
Copy full SHA for 702d586 - Browse repository at this point
Copy the full SHA 702d586View commit details -
Extract printing of "async " in a helper
Maxim committedJul 18, 2022 Configuration menu - View commit details
-
Copy full SHA for 046d1e3 - Browse repository at this point
Copy the full SHA 046d1e3View commit details -
Document ternary colon vs async arrow expression colon
Maxim committedJul 18, 2022 Configuration menu - View commit details
-
Copy full SHA for 41844e6 - Browse repository at this point
Copy the full SHA 41844e6View commit details -
Add extra test case for async arrow expressions in ternary true branches
Maxim committedJul 18, 2022 Configuration menu - View commit details
-
Copy full SHA for fcd3c32 - Browse repository at this point
Copy the full SHA fcd3c32View commit details -
Sort attribute variant cases on
hasAttributes
andfilterParsingAttrs
Maxim committedJul 18, 2022 Configuration menu - View commit details
-
Copy full SHA for d20b149 - Browse repository at this point
Copy the full SHA d20b149View commit details -
Document Lident "async" branch in
parseBracedOrRecordExpr
.Maxim committedJul 18, 2022 Configuration menu - View commit details
-
Copy full SHA for 3b17a08 - Browse repository at this point
Copy the full SHA 3b17a08View commit details -
Fix printing of await expression inside binary expressions
Maxim committedJul 18, 2022 Configuration menu - View commit details
-
Copy full SHA for bff364e - Browse repository at this point
Copy the full SHA bff364eView commit details -
Implement printing of parens for rhs of await expression correctly.
Maxim committedJul 18, 2022 Configuration menu - View commit details
-
Copy full SHA for c15dee0 - Browse repository at this point
Copy the full SHA c15dee0View commit details -
Configuration menu - View commit details
-
Copy full SHA for 5e9b914 - Browse repository at this point
Copy the full SHA 5e9b914View commit details