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

Properly remove ! from definite assignment assertions #658

Merged
merged 1 commit into from Oct 18, 2021

Conversation

alangpierce
Copy link
Owner

Fixes #639

Previously, the ! operator for class field declarations was not treated as a
type token, so it wasn't automatically removed at transpile. In most cases, this
wasn't relevant because the class field transform removes uninitialized fields
completely. However, there are two cases where it causes an issue:

  • disableESTransforms: true, which disables the class field transform.
  • Private fields, which are skipped by the class field transform.

In both cases, we can fix the issue by just setting the ! as a type token so
that it will naturally get removed by the TS transformer.

I also did a little refactoring to pull out the logic for handling individual
type tokens.

Fixes #639

Previously, the `!` operator for class field declarations was not treated as a
type token, so it wasn't automatically removed at transpile. In most cases, this
wasn't relevant because the class field transform removes uninitialized fields
completely. However, there are two cases where it causes an issue:
* `disableESTransforms: true`, which disables the class field transform.
* Private fields, which are skipped by the class field transform.

In both cases, we can fix the issue by just setting the `!` as a type token so
that it will naturally get removed by the TS transformer.

I also did a little refactoring to pull out the logic for handling individual
type tokens.
@codecov
Copy link

codecov bot commented Oct 18, 2021

Codecov Report

Merging #658 (0830175) into main (018ee1d) will increase coverage by 0.08%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #658      +/-   ##
==========================================
+ Coverage   82.58%   82.67%   +0.08%     
==========================================
  Files          56       56              
  Lines        5690     5932     +242     
  Branches     1344     1343       -1     
==========================================
+ Hits         4699     4904     +205     
- Misses        708      745      +37     
  Partials      283      283              
Impacted Files Coverage Δ
src/parser/plugins/types.ts 94.73% <100.00%> (+3.07%) ⬆️
src/parser/tokenizer/index.ts 79.95% <100.00%> (+0.22%) ⬆️
src/parser/traverser/statement.ts 82.59% <100.00%> (+0.43%) ⬆️
src/util/formatTokens.ts 70.58% <0.00%> (-10.06%) ⬇️
src/parser/util/identifier.ts 90.90% <0.00%> (-4.10%) ⬇️
src/util/shouldElideDefaultExport.ts 77.77% <0.00%> (-3.48%) ⬇️
src/util/getClassInfo.ts 87.85% <0.00%> (-1.85%) ⬇️
src/parser/plugins/jsx/index.ts 91.33% <0.00%> (-1.48%) ⬇️
src/identifyShadowedGlobals.ts 88.09% <0.00%> (-1.10%) ⬇️
src/parser/plugins/flow.ts 63.99% <0.00%> (-1.09%) ⬇️
... and 22 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 018ee1d...0830175. Read the comment docs.

@github-actions
Copy link

Benchmark results

Before this PR: 330.3 thousand lines per second
After this PR: 329.4 thousand lines per second

Measured change: 0.27% slower (0.96% slower to 0.18% faster)
Summary: Likely no significant difference

@alangpierce alangpierce merged commit ed17741 into main Oct 18, 2021
@alangpierce alangpierce deleted the fix-class-field-definite-assignment-assertions branch October 18, 2021 07:01
@alangpierce
Copy link
Owner Author

Published as 3.20.3.

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.

TypeScript definite assignment assertions are not removed for private class fields
1 participant