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

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

Closed
zipang opened this issue Nov 7, 2022 · 2 comments · Fixed by #769
Closed

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

zipang opened this issue Nov 7, 2022 · 2 comments · Fixed by #769

Comments

@zipang
Copy link

zipang commented Nov 7, 2022

Sucrase fails to parse some usages of the type helper $Call inside Flow code :

Example of code failing :

// @flow

type Account = $PropertyType<
  $Call<<T>($ReadOnlyArray<T>) => T>,
  'account'
>

Demo :

@zipang zipang changed the title Fail to parse some usages of Flow $Call (Unexpected token, expected ",") Failure to parse some usages of Flow $Call (Unexpected token, expected ",") Nov 7, 2022
@alangpierce
Copy link
Owner

Thanks for reporting! I think the bug here is that << being mis-tokenized as a left-shift operator. There are already some special cases to get >> working (based off of similar special cases in Babel), and at least one << case was handled recently in https://github.com/alangpierce/sucrase/pull/716/files#diff-0221cac4ed46c5209e9fe0f67d5f903e3f2069287eedc8a8502f3906f504ac2c , but looks like this is a case that was missed.

alangpierce added a commit that referenced this issue 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 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.
alangpierce added a commit that referenced this issue Nov 28, 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.
@zipang
Copy link
Author

zipang commented Nov 29, 2022

Thxx a lot ! :)

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 a pull request may close this issue.

2 participants