Skip to content

Conversation

asgerf
Copy link
Contributor

@asgerf asgerf commented Feb 3, 2025

Fixes a rare JSX parse error, reported in #18651.

We parse JavaScript files in two attempts: the first attempt only allows standard syntax and the second attempt includes various extensions, such as JSX and Flow.

This is because some syntax extensions can result in parse errors, even though the file is valid standard JS. For example, when the JSX parser sees a < token it has to guess whether this is a part of a JSX tag or a less-than operator. This guesswork is imperfect and if it guesses wrong, a valid file may be rejected.

The syntax error occurred in a case where the file was valid JSX but the Flow syntax extension caused a parsing error due to an incorrect guess about Flow syntax.

This PR changes parsing of .jsx files so that JSX syntax is enabled in the first attempt, where Flow syntax can not interfere. Note that Flow files use the .js extension and do permit JSX syntax, so we cannot outright disable JSX parsing for non-.jsx files.

@github-actions github-actions bot added the JS label Feb 3, 2025
@asgerf asgerf marked this pull request as ready for review February 4, 2025 08:37
@Copilot Copilot AI review requested due to automatic review settings February 4, 2025 08:37
@asgerf asgerf requested a review from a team as a code owner February 4, 2025 08:37
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again, by re-requesting a review.

@asgerf asgerf merged commit 3d3f07a into github:main Feb 4, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants