Fix JSX parsing failures in ternary expressions with nested JSX attributes#2937
Draft
Fix JSX parsing failures in ternary expressions with nested JSX attributes#2937
Conversation
…s and object literals
Add investigation notes and test case for a bug where JSX parsing produces
spurious syntax errors when:
1. A ternary expression has a parenthesized identifier in the truthy branch
2. The falsy branch contains JSX with multi-line attributes
3. JSX attributes contain nested JSX with function calls having multi-property object literals
Root cause: The speculative arrow function parser incorrectly succeeds when parsing
the ternary truthy branch '(x)' as an arrow function parameter list, consuming the
ternary ':' as a return type annotation colon, and then the type parsing error
recovery through JSX-like content coincidentally leaves the token at '{' (from
{a:1,b:2}), which passes the OpenBraceToken check for arrow function body.
The speculative parse commits to an incorrect interpretation and doesn't rewind,
causing cascading syntax errors for all subsequent JSX content.
Copilot
AI
changed the title
[WIP] Fix JSX parsing errors in nested ternary expressions
Fix JSX parsing failures in ternary expressions with nested JSX and multi-property object literals
Feb 28, 2026
…ulti-property object literals Port the missing `isMissingList(parameters)` check from TypeScript's `typeHasArrowFunctionBlockingParseError` to the Go parser. When the parser speculatively tries to parse `(identifier) :` as an arrow function with a return type annotation, the return type parsing can interpret `(<JSXElement ...)` as a parenthesized function type (since `<` starts type parameters). If the function type's parameter list is "missing" (no `(` found), TypeScript correctly detects this as a blocking parse error and aborts the speculative parse. The Go port was missing this check, causing the speculative parse to incorrectly succeed and consume tokens from the JSX content. Changes: - Add `isMissing` field to `NodeList` to track missing lists - Mark parameter lists as missing in `parseParameters` when `(` not found - Split FunctionType/ConstructorType from ParenthesizedType in `typeHasArrowFunctionBlockingParseError` to add the missing list check Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copilot
AI
changed the title
Fix JSX parsing failures in ternary expressions with nested JSX and multi-property object literals
Fix JSX parsing failures in ternary expressions with nested JSX attributes
Feb 28, 2026
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.
Valid TSX with ternary expressions containing parenthesized identifiers in the true branch and nested JSX with object literals in the false branch produces 30 spurious syntax errors. Standard
tscparses this correctly.Root cause
During speculative arrow function parsing,
(DEFAULT_NULL_VALUE) :is tried as an arrow signature with return type annotation. The return type parser encounters(<div ...and interprets<as the start of type parameters for a function type. This produces aFunctionTypenode with a missing parameter list (no(found).TypeScript's
typeHasArrowFunctionBlockingParseErrorcatches this viaisMissingList(parameters)and aborts the speculative parse. The Go port was missing this check, so the speculative parse incorrectly committed, consuming JSX tokens.Changes
ast.go: AddisMissingfield toNodeListwith accessor methods, porting TS'sMissingListconceptparser.go—parseParameters: Mark the parameter list as missing when(is not foundparser.go—typeHasArrowFunctionBlockingParseError: SplitFunctionType/ConstructorTypefromParenthesizedTypecase and add the missing parameter list check, matching the TS reference:Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.