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

[JavaScript] Fix const arrow functions in TSX #4114

Conversation

deathaxe
Copy link
Collaborator

Fixes #4112

This PR refactors JSX/TSX tag related contexts and arrow function detection to improve reliability, maintainability and fix some possible causes of former lockups as well as a conflict with generic arrow functions using constant type parameters.

It's a bit of fixing and cleaning.

Parsing performance is more or less unaffected.

This commit...

1. adds named contexts for parenthesized expressions
2. adds dedicated context for parenthesized expressions in typescript,
   to fail early when detecting type annotation without leaking
   `fail: arrow-function` to unrelated contexts.

   This may have had unexpected consequences.

3. re-arranges old-style type assertion syntax to group related contexts

   It was odd to see arrow function and expression related contexts
   between export/import statement related contexts.

4. optimizes expression/arrow function detection related contexts by removing
   redundant lookaheads and reduce required context switches.

Note: This commit does not change parsing behavior. It is just a reliability,
      maintainability and small performance fix.
This commit ...

1. drops `jsx-attribute-value` and implements value string patterns directly
   into `jsx-tag-attributes` context to simplify overall structure.

   This also drops a `jsx-tag` include, which doesn't seem to make any sense,
   as nested tags within jsx tags are not supported. It may even be reason for
   various lockups which JSX/TSX suffered from in the past.

2. adds named contexts for jsx tag value strings.

3. scopes jsx tag value strings `meta.string`.

As a result syntax of JSX tag attributes is a bit more permissive
with regards to missing `=` operators.
This commit...

1. converts anonymous JSX child tag contexts to named contexts
2. adds tests to verify deep nesting works
This commit just moves some JSX/TSX related contexts to group and bring them
into a more logical order.
This commit reduces amount of contexts pushed on stack
to handle unmatched tags. As new merged context shares patterns with
`jsx-expect-tag-end` compiled syntax cache doesn't change.
@deathaxe deathaxe force-pushed the pr/javascript/fix-tsx-generic-arrow-functions branch from 43e4f30 to 28dbfd9 Compare December 15, 2024 21:35
@jfcherng jfcherng merged commit 737d31d into sublimehq:master Dec 21, 2024
1 check passed
@deathaxe deathaxe deleted the pr/javascript/fix-tsx-generic-arrow-functions branch December 21, 2024 18:22
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.

[JavaScript] Required support for TSX const generics
3 participants