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:
Allan Guwatudde
2020-03-19 21:40:43 +03:00
committed by GitHub
parent e2156a1535
commit a83ce339c9
6 changed files with 113 additions and 1 deletions

View File

@@ -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: