JS: Use JSX syntax in first attempt when extension is .jsx #18658
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.