@@ -4119,17 +4119,32 @@ namespace ts {
41194119 return finishNode ( node ) ;
41204120 }
41214121
4122- function parseJsxChild ( ) : JsxChild {
4123- switch ( token ( ) ) {
4122+ function parseJsxChild ( openingTag : JsxOpeningElement | JsxOpeningFragment , token : JsxTokenSyntaxKind ) : JsxChild | undefined {
4123+ switch ( token ) {
4124+ case SyntaxKind . EndOfFileToken :
4125+ // If we hit EOF, issue the error at the tag that lacks the closing element
4126+ // rather than at the end of the file (which is useless)
4127+ if ( isJsxOpeningFragment ( openingTag ) ) {
4128+ parseErrorAtPosition ( openingTag . pos , openingTag . end - openingTag . pos , Diagnostics . JSX_fragment_has_no_corresponding_closing_tag ) ;
4129+ }
4130+ else {
4131+ const openingTagName = openingTag . tagName ;
4132+ parseErrorAtPosition ( openingTagName . pos , openingTagName . end - openingTagName . pos , Diagnostics . JSX_element_0_has_no_corresponding_closing_tag , getTextOfNodeFromSourceText ( sourceText , openingTagName ) ) ;
4133+ }
4134+ return undefined ;
4135+ case SyntaxKind . LessThanSlashToken :
4136+ case SyntaxKind . ConflictMarkerTrivia :
4137+ return undefined ;
41244138 case SyntaxKind . JsxText :
41254139 case SyntaxKind . JsxTextAllWhiteSpaces :
41264140 return parseJsxText ( ) ;
41274141 case SyntaxKind . OpenBraceToken :
4128- return parseJsxExpression ( /*inExpressionContext*/ false ) ! ;
4142+ return parseJsxExpression ( /*inExpressionContext*/ false ) ;
41294143 case SyntaxKind . LessThanToken :
41304144 return parseJsxElementOrSelfClosingElementOrFragment ( /*inExpressionContext*/ false ) ;
4145+ default :
4146+ return Debug . assertNever ( token ) ;
41314147 }
4132- Debug . fail ( "Unknown JSX child kind " + token ( ) ) ;
41334148 }
41344149
41354150 function parseJsxChildren ( openingTag : JsxOpeningElement | JsxOpeningFragment ) : NodeArray < JsxChild > {
@@ -4139,34 +4154,12 @@ namespace ts {
41394154 parsingContext |= 1 << ParsingContext . JsxChildren ;
41404155
41414156 while ( true ) {
4142- currentToken = scanner . reScanJsxToken ( ) ;
4143- if ( token ( ) === SyntaxKind . LessThanSlashToken ) {
4144- // Closing tag
4145- break ;
4146- }
4147- else if ( token ( ) === SyntaxKind . EndOfFileToken ) {
4148- // If we hit EOF, issue the error at the tag that lacks the closing element
4149- // rather than at the end of the file (which is useless)
4150- if ( isJsxOpeningFragment ( openingTag ) ) {
4151- parseErrorAtPosition ( openingTag . pos , openingTag . end - openingTag . pos , Diagnostics . JSX_fragment_has_no_corresponding_closing_tag ) ;
4152- }
4153- else {
4154- const openingTagName = openingTag . tagName ;
4155- parseErrorAtPosition ( openingTagName . pos , openingTagName . end - openingTagName . pos , Diagnostics . JSX_element_0_has_no_corresponding_closing_tag , getTextOfNodeFromSourceText ( sourceText , openingTagName ) ) ;
4156- }
4157- break ;
4158- }
4159- else if ( token ( ) === SyntaxKind . ConflictMarkerTrivia ) {
4160- break ;
4161- }
4162- const child = parseJsxChild ( ) ;
4163- if ( child ) {
4164- list . push ( child ) ;
4165- }
4157+ const child = parseJsxChild ( openingTag , currentToken = scanner . reScanJsxToken ( ) ) ;
4158+ if ( ! child ) break ;
4159+ list . push ( child ) ;
41664160 }
41674161
41684162 parsingContext = saveParsingContext ;
4169-
41704163 return createNodeArray ( list , listPos ) ;
41714164 }
41724165
0 commit comments