fix jsx error location when empty JsxExpression precedes failing child#63542
Closed
harsha-cpp wants to merge 1 commit into
Closed
fix jsx error location when empty JsxExpression precedes failing child#63542harsha-cpp wants to merge 1 commit into
harsha-cpp wants to merge 1 commit into
Conversation
Contributor
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.
Member
|
This doesn't meet the 6.0 patch bar, see #62963. New development should generally happen in the typescript-go repo right now. |
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 #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.