Skip to content

fix jsx error location when empty JsxExpression precedes failing child#63542

Closed
harsha-cpp wants to merge 1 commit into
microsoft:mainfrom
harsha-cpp:fix/jsx-comment-steals-error-location
Closed

fix jsx error location when empty JsxExpression precedes failing child#63542
harsha-cpp wants to merge 1 commit into
microsoft:mainfrom
harsha-cpp:fix/jsx-comment-steals-error-location

Conversation

@harsha-cpp

Copy link
Copy Markdown

fixes #63358.

problem: when a JSX comment {/* */} appears before a type-incompatible child expression on the same line, the error squiggle lands on the comment instead of the failing expression. getElaborationElementForJsxChild returned an elaboration element for all JsxExpression nodes including empty ones (comments), giving the comment a tuple index and making it the errorNode for the subsequent type mismatch.

fix: guard the JsxExpression case to break (skip) when child.expression is undefined, matching the behavior of getSemanticJsxChildren and checkJsxChildren which already treat empty JsxExpression nodes as non-children.

Copilot AI review requested due to automatic review settings June 7, 2026 13:00
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Jun 7, 2026
@typescript-automation typescript-automation Bot added For Backlog Bug PRs that fix a backlog bug labels Jun 7, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a compiler regression test to ensure empty JSX comment expressions ({/* ... */}) don’t affect diagnostic error locations, along with a checker fix to skip empty JsxExpression nodes during child analysis.

Changes:

  • Added a new TSX compiler test case covering comment-before/comment-after scenarios for JSX children diagnostics.
  • Updated the type checker to ignore empty JsxExpression nodes when computing the error node / inner expression mapping.
  • Added new baselines (.errors.txt, .types, .symbols, .js) for the test.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/cases/compiler/jsxCommentExpressionDoesNotStealErrorLocation.tsx New regression test exercising diagnostic location behavior around {/* ... */}.
tests/baselines/reference/jsxCommentExpressionDoesNotStealErrorLocation.types New expected types baseline output for the test.
tests/baselines/reference/jsxCommentExpressionDoesNotStealErrorLocation.symbols New expected symbols baseline output for the test.
tests/baselines/reference/jsxCommentExpressionDoesNotStealErrorLocation.js New expected JS emit baseline output for the test.
tests/baselines/reference/jsxCommentExpressionDoesNotStealErrorLocation.errors.txt New expected diagnostics baseline emphasizing correct error spans.
src/compiler/checker.ts Skips empty JsxExpression nodes when selecting an error node / inner expression.
Comments suppressed due to low confidence (1)

src/compiler/checker.ts:1

  • break only exits the switch, not necessarily the surrounding iteration. If there is any per-iteration logic after the switch, this does not actually “skip” the empty JSX expression and could still affect nameType alignment. Prefer restructuring to avoid the ambiguous control flow (e.g., if (child.kind === SyntaxKind.JsxExpression && child.expression) { return ... } and otherwise continue scanning), or use a labeled continue if this is inside a loop and you truly intend to skip the rest of the iteration.

@RyanCavanaugh

Copy link
Copy Markdown
Member

This doesn't meet the 6.0 patch bar, see #62963. New development should generally happen in the typescript-go repo right now.

@github-project-automation github-project-automation Bot moved this from Not started to Done in PR Backlog Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

TSX error location error with location and JSX comment

3 participants