Fixed a crash on JSX emit trying to emit unexpectedly recovered BinaryExpression in a JSX attribute - #64470
Open
Mateusz Burzyński (Andarist) wants to merge 2 commits into
Conversation
…xpressions parseJsxAttributeValue called parseJsxElementOrSelfClosingElementOrFragment with mustBeUnary=false, so the "JSX expressions must have one parent element" recovery could return a comma BinaryExpression as a JsxAttribute initializer, violating the JsxAttributeValue contract and crashing the react/react-jsx transforms. Fixes microsoft#64458
|
This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise. |
Copilot started reviewing on behalf of
Mateusz Burzyński (Andarist)
September 26, 2026 17:33
View session
| return p.parseJsxElementOrSelfClosingElementOrFragment(true /*inExpressionContext*/, -1, nil, false) | ||
| // An attribute value must be a single JsxAttributeValue, so don't allow the sibling-element | ||
| // recovery to wrap it in a synthetic binary expression. | ||
| return p.parseJsxElementOrSelfClosingElementOrFragment(true /*inExpressionContext*/, -1 /*topInvalidNodePosition*/, nil /*openingTag*/, true /*mustBeUnary*/) |
Contributor
Author
There was a problem hiding this comment.
I think it's best to handle this here - where the bad data was created. All of the other code just doesn't expect BinaryExpression here given:
type JsxAttributeValue = StringLiteral | JsxExpression | JsxElement | JsxSelfClosingElement | JsxFragment
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The targeted parser correction preserves AST invariants and includes relevant regression baselines.
Review effort: Balanced
Findings: None
What changed in this PR
Prevents JSX emit crashes by disallowing synthetic binary-expression recovery within JSX attribute values.
Changes:
- Enforces the
JsxAttributeValueAST invariant during parser recovery. - Adds regression coverage for classic and automatic JSX emit.
- Updates affected diagnostic and emit baselines.
| File | Description |
|---|---|
tsc/internal/parser/parser.go |
Restricts sibling-element recovery in attribute values. |
tsc/testdata/tests/cases/compiler/jsxAttributeInitializerMultipleElementsNoCrash.tsx |
Adds the crash regression case. |
tsc/testdata/baselines/reference/compiler/jsxAttributeValueBinaryExpression.js |
Updates existing emit expectations. |
tsc/testdata/baselines/reference/compiler/jsxAttributeValueBinaryExpression.errors.txt |
Updates existing diagnostics. |
tsc/testdata/baselines/reference/compiler/jsxAttributeInitializerMultipleElementsNoCrash(jsx=react).js |
Records classic JSX emit. |
tsc/testdata/baselines/reference/compiler/jsxAttributeInitializerMultipleElementsNoCrash(jsx=react).errors.txt |
Records classic JSX diagnostics. |
tsc/testdata/baselines/reference/compiler/jsxAttributeInitializerMultipleElementsNoCrash(jsx=react-jsx).js |
Records automatic JSX emit. |
tsc/testdata/baselines/reference/compiler/jsxAttributeInitializerMultipleElementsNoCrash(jsx=react-jsx).errors.txt |
Records automatic JSX diagnostics. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 crash reported here #64458 (comment)