mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 01:04:49 -05:00
Fix poor error span for unclosed JSX tags in the presence of whitespace/comments (#37419)
* Improve jsx tag error span * Move solution to parseJsxChild func * Add tests and update baselines * Update comment in src/compiler/parser.ts Co-Authored-By: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com> * Use skipTrivia to check for whitespaces and other trivia * Import React into errorSpanForUnclosedJsxTag.tsx * . * . Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
This commit is contained in:
@@ -4545,7 +4545,11 @@ namespace ts {
|
||||
parseErrorAtRange(openingTag, Diagnostics.JSX_fragment_has_no_corresponding_closing_tag);
|
||||
}
|
||||
else {
|
||||
parseErrorAtRange(openingTag.tagName, Diagnostics.JSX_element_0_has_no_corresponding_closing_tag, getTextOfNodeFromSourceText(sourceText, openingTag.tagName));
|
||||
// We want the error span to cover only 'Foo.Bar' in < Foo.Bar >
|
||||
// or to cover only 'Foo' in < Foo >
|
||||
const tag = openingTag.tagName;
|
||||
const start = skipTrivia(sourceText, tag.pos);
|
||||
parseErrorAt(start, tag.end, Diagnostics.JSX_element_0_has_no_corresponding_closing_tag, getTextOfNodeFromSourceText(sourceText, openingTag.tagName));
|
||||
}
|
||||
return undefined;
|
||||
case SyntaxKind.LessThanSlashToken:
|
||||
|
||||
Reference in New Issue
Block a user