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

Disable the class fields transform when disableESTransforms is set #625

Merged
merged 1 commit into from Jun 23, 2021

Conversation

alangpierce
Copy link
Owner

When disableESTransforms is specified, the class transform can almost entirely
be skipped, but we still need to do some work:

  • TS constructor initializers (e.g. constructor params with readonly or
    private) need to be transformed to assignments within the constructor.
  • Fields marked declare need to be removed. Uninitialized fields not marked
    declare are preserved, matching the ES spec and the useDefineForClassFields
    flag in TS.

For now, we still use the getClassInfo code path but give alternate results.
In the future we can hopefully simplify that code path, and possibly change
declare parsing so the whole line consists of type tokens that will naturally
be erased.

When disableESTransforms is specified, the class transform can almost entirely
be skipped, but we still need to do some work:
* TS constructor initializers (e.g. constructor params with `readonly` or
  `private`) need to be transformed to assignments within the constructor.
* Fields marked `declare` need to be removed. Uninitialized fields not marked
  declare are preserved, matching the ES spec and the `useDefineForClassFields`
  flag in TS.

For now, we still use the `getClassInfo` code path but give alternate results.
In the future we can hopefully simplify that code path, and possibly change
`declare` parsing so the whole line consists of type tokens that will naturally
be erased.
@codecov
Copy link

codecov bot commented Jun 22, 2021

Codecov Report

Merging #625 (333f9be) into main (6b6c0d7) will decrease coverage by 0.04%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #625      +/-   ##
==========================================
- Coverage   82.20%   82.16%   -0.05%     
==========================================
  Files          56       56              
  Lines        5874     5646     -228     
  Branches     1326     1330       +4     
==========================================
- Hits         4829     4639     -190     
+ Misses        762      724      -38     
  Partials      283      283              
Impacted Files Coverage Δ
src/parser/plugins/flow.ts 65.06% <100.00%> (+1.34%) ⬆️
src/transformers/RootTransformer.ts 93.65% <100.00%> (+0.03%) ⬆️
src/util/getClassInfo.ts 89.70% <100.00%> (+2.48%) ⬆️
src/Options-gen-types.ts 75.00% <0.00%> (-25.00%) ⬇️
src/parser/index.ts 77.77% <0.00%> (-7.94%) ⬇️
src/computeSourceMap.ts 83.33% <0.00%> (-5.56%) ⬇️
src/util/getNonTypeIdentifiers.ts 94.44% <0.00%> (-5.56%) ⬇️
src/parser/plugins/types.ts 91.66% <0.00%> (-3.34%) ⬇️
src/parser/tokenizer/readWord.ts 82.35% <0.00%> (-3.02%) ⬇️
src/parser/traverser/util.ts 86.20% <0.00%> (-2.17%) ⬇️
... 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 6b6c0d7...333f9be. Read the comment docs.

@github-actions
Copy link

Benchmark results

Before this PR: 322.4 thousand lines per second
After this PR: 324.2 thousand lines per second

Measured change: 0.56% faster (0.58% slower to 1.51% faster)
Summary: Likely no significant difference

@alangpierce alangpierce merged commit 29970ce into main Jun 23, 2021
@alangpierce alangpierce deleted the skip-class-transform-when-disabling-es-transforms branch June 23, 2021 07:29
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

1 participant