Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 3 additions & 5 deletions tests/baselines/reference/tsxFragmentErrors.errors.txt
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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.

Expand Down
6 changes: 3 additions & 3 deletions tests/baselines/reference/tsxFragmentErrors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
5 changes: 3 additions & 2 deletions tests/baselines/reference/tsxFragmentErrors.types
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions tests/cases/fourslash/jsxElementMissingOpeningTagNoCrash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/// <reference path="fourslash.ts" />

//@Filename: file.tsx
//// declare function Foo(): any;
//// let x = <></Fo/*$*/o>;

verify.quickInfoAt("$", "let Foo: any");