fix jsx error location when empty JsxExpression precedes failing child#63542
fix jsx error location when empty JsxExpression precedes failing child#63542harsha-cpp wants to merge 1 commit into
Conversation
|
@harsha-cpp please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
There was a problem hiding this comment.
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
JsxExpressionnodes 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
breakonly exits theswitch, not necessarily the surrounding iteration. If there is any per-iteration logic after theswitch, this does not actually “skip” the empty JSX expression and could still affectnameTypealignment. 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 labeledcontinueif this is inside a loop and you truly intend to skip the rest of the iteration.
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.getElaborationElementForJsxChildreturned an elaboration element for allJsxExpressionnodes including empty ones (comments), giving the comment a tuple index and making it theerrorNodefor the subsequent type mismatch.fix: guard the
JsxExpressioncase to break (skip) whenchild.expressionis undefined, matching the behavior ofgetSemanticJsxChildrenandcheckJsxChildrenwhich already treat emptyJsxExpressionnodes as non-children.