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

Fix nullish coalescing when the RHS is an object literal #516

Merged
merged 3 commits into from
Mar 22, 2020

Conversation

alangpierce
Copy link
Owner

@alangpierce alangpierce commented Mar 22, 2020

Fixes #505

The RHS is meant to be transpiled into an expression arrow function, but if the
expression is an object literal, it gets interpreted as a block body. To fix, we
can unconditionally surround the arrow body in parens. This is a little ugly in
that it leaves an extra space, but avoiding that is probably more trouble than
it's worth.

Also fix two issues with test infra:

  • The build was only running the very last build configuration due to what seems to be a
    breaking change in Travis. Updated the yaml file to use jobs instead of matrix, which
    seems to work better.
  • Three Babel tests had broken due to fixture tests that were testing unpinned behavior (looks
    like regex transformation and preset-env behavior). I was hoping to fix them by pinning the
    dependencies or updating to latest Babel, but ended up just updating the expected test code
    for now. I confirmed that this was a regression on the Babel end rather than anything caused by
    a Sucrase change.

Fixes #505

The RHS is meant to be transpiled into an expression arrow function, but if the
expression is an object literal, it gets interpreted as a block body. To fix, we
can unconditionally surround the arrow body in parens. This is a little ugly in
that it leaves an extra space, but avoiding that is probably more trouble than
it's worth.
@codecov-io
Copy link

codecov-io commented Mar 22, 2020

Codecov Report

Merging #516 into master will decrease coverage by 0.01%.
The diff coverage is 80.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #516      +/-   ##
==========================================
- Coverage   82.71%   82.69%   -0.02%     
==========================================
  Files          55       55              
  Lines        5617     5618       +1     
  Branches     1263     1264       +1     
==========================================
  Hits         4646     4646              
  Misses        681      681              
- Partials      290      291       +1     
Impacted Files Coverage Δ
src/transformers/ReactHotLoaderTransformer.ts 94.73% <50.00%> (-5.27%) ⬇️
src/TokenProcessor.ts 92.72% <100.00%> (ø)
...transformers/OptionalChainingNullishTransformer.ts 84.93% <100.00%> (ø)

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 c274a7e...8c64cad. Read the comment docs.

@alangpierce alangpierce merged commit 0d91fd2 into master Mar 22, 2020
@alangpierce alangpierce deleted the fix-nullish-coalescing-object-rhs branch March 22, 2020 05:55
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.

Nullish coalesce fails when returning an empty object
2 participants