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

Conversation

alangpierce
Copy link
Owner

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.

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.
@codecov-io
Copy link

Codecov Report

Merging #497 into master will increase coverage by 0.03%.
The diff coverage is 93.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #497      +/-   ##
==========================================
+ Coverage   82.59%   82.63%   +0.03%     
==========================================
  Files          54       55       +1     
  Lines        5545     5355     -190     
  Branches     1238     1253      +15     
==========================================
- Hits         4580     4425     -155     
+ Misses        678      646      -32     
+ Partials      287      284       -3
Impacted Files Coverage Δ
src/parser/traverser/expression.ts 87.78% <100%> (-0.04%) ⬇️
src/HelperManager.ts 100% <100%> (ø) ⬆️
src/parser/tokenizer/index.ts 77.41% <100%> (+0.1%) ⬆️
...transformers/OptionalChainingNullishTransformer.ts 90.74% <100%> (+0.94%) ⬆️
src/TokenProcessor.ts 92.72% <100%> (+0.89%) ⬆️
src/util/isAsyncOperation.ts 82.35% <82.35%> (ø)
src/Options-gen-types.ts 50% <0%> (-50%) ⬇️
src/util/getDeclarationInfo.ts 80% <0%> (-20%) ⬇️
src/util/elideImportEquals.ts 81.81% <0%> (-18.19%) ⬇️
src/parser/index.ts 77.77% <0%> (-7.94%) ⬇️
... and 25 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d1a9731...c2d9659. Read the comment docs.

@alangpierce alangpierce merged commit 626ee5e into master Jan 1, 2020
@alangpierce alangpierce deleted the implement-async-optional-chain-nullish branch January 1, 2020 23:50
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.

None yet

2 participants