Repository navigation
Parse JSX elements and fragments as primary expressions - #65725
magic-akari wants to merge 2 commits into
Conversation
Continue parsing member access, calls, and tagged templates after JSX, including across line breaks. Check for adjacent roots before parsing type arguments to preserve the missing-parent diagnostic.
There was a problem hiding this comment.
🟡 Changes recommended
The sibling-probe logic can cause quadratic parsing and discard recognizable JSX siblings with descendant errors, suppressing TS2657 and degrading formatter/editor recovery.
2 open issues
What changed in this PR
This PR addresses #65724 by parsing JSX elements and fragments as primary expressions, allowing the compiler to preserve expression continuations across line breaks.
Changes:
- Enables member access, calls, and tagged templates after JSX in
.jsxand.tsx. - Moves adjacent-root recovery into a separate parser helper.
- Adds continuation regression tests and updates affected diagnostic, emit, and type baselines.
| File | Description |
|---|---|
tsc/testdata/tests/cases/compiler/jsxPrimaryExpressionContinuations.tsx |
Tests continuations, explicit semicolons, and adjacent roots. |
tsc/testdata/baselines/reference/conformance/jsxInvalidEsprimaTestSuite.types |
Updates inferred expression types for malformed JSX. |
tsc/testdata/baselines/reference/conformance/jsxInvalidEsprimaTestSuite.js |
Updates malformed-JSX emit expectations. |
tsc/testdata/baselines/reference/conformance/jsxInvalidEsprimaTestSuite.errors.txt |
Updates malformed-JSX diagnostics. |
tsc/testdata/baselines/reference/conformance/checkJsxNamespaceNamesQuestionableForms.types |
Updates types for malformed namespace syntax. |
tsc/testdata/baselines/reference/conformance/checkJsxNamespaceNamesQuestionableForms.js |
Updates namespace-syntax emit expectations. |
tsc/testdata/baselines/reference/conformance/checkJsxNamespaceNamesQuestionableForms.errors.txt |
Updates namespace-syntax diagnostics. |
tsc/testdata/baselines/reference/compiler/jsxPrimaryExpressionContinuations.js |
Records continuation and recovery emit. |
tsc/testdata/baselines/reference/compiler/jsxPrimaryExpressionContinuations.errors.txt |
Records adjacent-root errors and accepted continuations. |
tsc/internal/parser/parser.go |
Integrates JSX primary expressions and revises recovery. |
Review effort: Balanced
| state := p.mark() | ||
| element := p.parseJsxElementOrSelfClosingElementOrFragment(true /*inExpressionContext*/, nil /*openingTag*/) |
| if len(p.diagnostics) != state.diagnosticsLen && first.Flags&ast.NodeFlagsThisNodeHasError == 0 { | ||
| // Leave '<' for type arguments or a comparison after a well-formed JSX root. | ||
| p.rewind(state) | ||
| break |
|
TypeScript Bot (@typescript-bot) test it |
|
I have a local fix for both issues Copilot flagged in the JSX parser. It adds about 30 lines of Go. Do you think it’s worth including in this PR? |
|
Hey Daniel Rosenwasser (@DanielRosenwasser), the results of running the DT tests are ready. Everything looks the same! |
|
Daniel Rosenwasser (@DanielRosenwasser) Here are the results of running the user tests with tsc comparing Everything looks good! |
|
Daniel Rosenwasser (@DanielRosenwasser) Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Daniel Rosenwasser (@DanielRosenwasser) Here are the results of running the top 400 repos with tsc comparing Everything looks good! |

The parser returned too early after reading a JSX element or fragment. This could split a valid expression at a line break or produce a spurious semicolon error on the same line.
This change parses JSX elements and fragments as primary expressions so member access, calls, and tagged templates can follow them in both
.jsxand.tsx. Adjacent JSX roots still report TS2657.