Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

Done, but do not merge yet: Async/Await syntax. #600

Merged
merged 22 commits into from
Jul 18, 2022

Commits on Jul 18, 2022

  1. Implement parsing of await expressions.

    operand-expr += `await` unary-expr
    Maxim committed Jul 18, 2022
    Configuration menu
    Copy the full SHA
    21c01e6 View commit details
    Browse the repository at this point in the history
  2. Implement parsing of async expressions

    operand-expr += `async` es6-arrow-expression
    Maxim committed Jul 18, 2022
    Configuration menu
    Copy the full SHA
    5995738 View commit details
    Browse the repository at this point in the history
  3. Make "await". and "async" non-keywords.

    Existing code using async/await as identifiers in e.g. record field names will keep working.
    Maxim committed Jul 18, 2022
    Configuration menu
    Copy the full SHA
    454d5b6 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    686fa53 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    5c91bc4 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    03db389 View commit details
    Browse the repository at this point in the history
  7. Make sure the "async" identifier can be used without being interprete…

    …d as async arrow function
    Maxim committed Jul 18, 2022
    Configuration menu
    Copy the full SHA
    9e711a4 View commit details
    Browse the repository at this point in the history
  8. Make await a keyword again.

    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 committed Jul 18, 2022
    Configuration menu
    Copy the full SHA
    d0b7cb1 View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    0283e8d View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    dc85c21 View commit details
    Browse the repository at this point in the history
  11. Refactor code style "async" token lookahead

    Maxim committed Jul 18, 2022
    Configuration menu
    Copy the full SHA
    66defd5 View commit details
    Browse the repository at this point in the history
  12. Rename @await/@async to @res.await/@res.async

    Maxim committed Jul 18, 2022
    Configuration menu
    Copy the full SHA
    ff69dfa View commit details
    Browse the repository at this point in the history
  13. Configuration menu
    Copy the full SHA
    3d5af74 View commit details
    Browse the repository at this point in the history
  14. Sort variant cases isExprStart alphabetically

    Maxim committed Jul 18, 2022
    Configuration menu
    Copy the full SHA
    702d586 View commit details
    Browse the repository at this point in the history
  15. Extract printing of "async " in a helper

    Maxim committed Jul 18, 2022
    Configuration menu
    Copy the full SHA
    046d1e3 View commit details
    Browse the repository at this point in the history
  16. Configuration menu
    Copy the full SHA
    41844e6 View commit details
    Browse the repository at this point in the history
  17. Configuration menu
    Copy the full SHA
    fcd3c32 View commit details
    Browse the repository at this point in the history
  18. Configuration menu
    Copy the full SHA
    d20b149 View commit details
    Browse the repository at this point in the history
  19. Configuration menu
    Copy the full SHA
    3b17a08 View commit details
    Browse the repository at this point in the history
  20. Configuration menu
    Copy the full SHA
    bff364e View commit details
    Browse the repository at this point in the history
  21. Configuration menu
    Copy the full SHA
    c15dee0 View commit details
    Browse the repository at this point in the history
  22. Update CHANGELOG.md

    cristianoc committed Jul 18, 2022
    Configuration menu
    Copy the full SHA
    5e9b914 View commit details
    Browse the repository at this point in the history