Don't parse out a name for JSX fragments (#52818)

This commit is contained in:
Jake Bailey 2023-02-17 10:55:56 -08:00 committed by GitHub
parent ddfec78f55
commit a3a4993937
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 14 deletions

View File

@ -6151,10 +6151,7 @@ namespace Parser {
function parseJsxClosingFragment(inExpressionContext: boolean): JsxClosingFragment {
const pos = getNodePos();
parseExpected(SyntaxKind.LessThanSlashToken);
if (tokenIsIdentifierOrKeyword(token())) {
parseErrorAtRange(parseJsxElementName(), Diagnostics.Expected_corresponding_closing_tag_for_JSX_fragment);
}
if (parseExpected(SyntaxKind.GreaterThanToken, /*diagnostic*/ undefined, /*shouldAdvance*/ false)) {
if (parseExpected(SyntaxKind.GreaterThanToken, Diagnostics.Expected_corresponding_closing_tag_for_JSX_fragment, /*shouldAdvance*/ false)) {
// manually advance the scanner in order to look for jsx text inside jsx
if (inExpressionContext) {
nextToken();

View File

@ -1,4 +1,4 @@
tests/cases/conformance/jsx/file.tsx(9,1): error TS2657: JSX expressions must have one parent element.
tests/cases/conformance/jsx/file.tsx(9,7): error TS2304: Cannot find name 'div'.
tests/cases/conformance/jsx/file.tsx(9,7): error TS17015: Expected corresponding closing tag for JSX fragment.
tests/cases/conformance/jsx/file.tsx(9,11): error TS17014: JSX fragment has no corresponding closing tag.
tests/cases/conformance/jsx/file.tsx(11,17): error TS1005: '</' expected.
@ -14,16 +14,14 @@ tests/cases/conformance/jsx/file.tsx(11,17): error TS1005: '</' expected.
declare var React: any;
<>hi</div> // Error
~~~~~~~~~~~~~~~~~~~
~~~
!!! error TS2304: Cannot find name 'div'.
~~~
!!! error TS17015: Expected corresponding closing tag for JSX fragment.
~~~~~~~~~
<>eof // Error
~~~~~~~~~~~~~~~~
!!! error TS2657: JSX expressions must have one parent element.
~~
!!! error TS17014: JSX fragment has no corresponding closing tag.

View File

@ -12,6 +12,6 @@ declare var React: any;
<>eof // Error
//// [file.js]
React.createElement(React.Fragment, null, "hi") // Error
, // Error
React.createElement(React.Fragment, null, "eof // Error");
React.createElement(React.Fragment, null, "hi");
div > // Error
React.createElement(React.Fragment, null, "eof // Error");

View File

@ -10,8 +10,9 @@ declare var React: any;
>React : any
<>hi</div> // Error
><>hi</div> // Error<>eof // Error : JSX.Element
><>hi</div> : JSX.Element
><>hi</ : JSX.Element
>div> // Error<>eof // Error : boolean
>div : any
<>eof // Error
><>eof // Error : JSX.Element

View File

@ -0,0 +1,7 @@
/// <reference path="fourslash.ts" />
//@Filename: file.tsx
//// declare function Foo(): any;
//// let x = <></Fo/*$*/o>;
verify.quickInfoAt("$", "let Foo: any");