Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix parsing of << within a type #769

Merged
merged 2 commits into from
Nov 28, 2022
Merged

Conversation

alangpierce
Copy link
Owner

@alangpierce alangpierce commented Nov 27, 2022

Fixes #758

There was already some logic from #716 to handle cases like f<<T>() => void>, where we're transitioning from a non-type context to a type context and need to detect if << is actually two open-type-parameter/argument tokens. There was a simpler missing case, though, which is that << is never allowed within a type, so we should tokenize as a simple < in a
type context. To handle the various cases correctly, this extra logic needs to only happen for <<, and this PR also adds
some additional comments explaining the nuances.

Fixes #758

There was already some logic from #716 to handle cases like `f<<T>() => void>`,
where we're transitioning from a non-type context to a type context and need to
detect if `<<` is actually two open-type-parameter/argument tokens. There was a
simpler missing case, though, which is that `<<` is never allowed within a type,
so we should exit early with a simple `<` in a type context. There was already a
similar case for `>`, so this just uses the same logic for `<`. This fixes the
same issue in TS and Flow.
@codecov
Copy link

codecov bot commented Nov 27, 2022

Codecov Report

Merging #769 (e0251ff) into main (6ff7348) will increase coverage by 0.03%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #769      +/-   ##
==========================================
+ Coverage   87.52%   87.56%   +0.03%     
==========================================
  Files          55       55              
  Lines        5886     5888       +2     
  Branches     1394     1395       +1     
==========================================
+ Hits         5152     5156       +4     
+ Misses        465      464       -1     
+ Partials      269      268       -1     
Impacted Files Coverage Δ
src/parser/plugins/typescript.ts 87.48% <ø> (+0.24%) ⬆️
src/parser/tokenizer/index.ts 86.37% <100.00%> (+0.05%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@github-actions
Copy link

github-actions bot commented Nov 27, 2022

Benchmark results

Before this PR: 378.8 thousand lines per second
After this PR: 381 thousand lines per second

Measured change: 0.59% faster (0.31% slower to 1.27% faster)
Summary: Likely no significant difference

@alangpierce alangpierce merged commit 473a09e into main Nov 28, 2022
@alangpierce alangpierce deleted the fix-incorrect-left-shift-in-types branch November 28, 2022 06:02
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failure to parse some usages of Flow $Call (Unexpected token, expected ",")
1 participant