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

Allow await expressions in optional chaining and nullish coalescing #497

Merged
merged 1 commit into from
Jan 1, 2020

Commits on Jan 1, 2020

  1. Allow await expressions in optional chaining and nullish coalescing

    Progress toward #461
    
    Tech plan:
    https://github.com/alangpierce/sucrase/wiki/Sucrase-Optional-Chaining-and-Nullish-Coalescing-Technical-Plan
    
    We now scan for an await keyword to indicate that the nullish coalescing or
    optional chaining operation is an async one, and in that case, call a different
    helper and emit async arrow functions instead of regular ones.
    
    This needed a few extra pieces of information in the token structure:
    * We now keep track of the scope depth to distinguish awaits inside inner async
      functions.
    * We use a token field to mark that the start token is an async operation.
    * We now track the start token for each nullish coalescing operation so that we
      can reference it to determine whether to emit an async arrow function.
    
    The extra token state and the duplicated helpers are all a bit ugly, but
    hopefully there won't be much more complexity beyond this, and I may investigate
    ways to store the token state in a more concise way. And, of course, this
    transform will go away eventually when optional chaining is available in node.
    alangpierce committed Jan 1, 2020
    Configuration menu
    Copy the full SHA
    c2d9659 View commit details
    Browse the repository at this point in the history