@@ -1163,7 +1163,7 @@ namespace ts {
11631163 return node ;
11641164 }
11651165
1166- function createMissingNode ( kind : SyntaxKind , reportAtCurrentPosition : boolean , diagnosticMessage : DiagnosticMessage , arg0 ?: any ) : Node {
1166+ function createMissingNode < T extends Node > ( kind : T [ "kind" ] , reportAtCurrentPosition : boolean , diagnosticMessage : DiagnosticMessage , arg0 ?: any ) : T {
11671167 if ( reportAtCurrentPosition ) {
11681168 parseErrorAtPosition ( scanner . getStartPos ( ) , 0 , diagnosticMessage , arg0 ) ;
11691169 }
@@ -1172,15 +1172,15 @@ namespace ts {
11721172 }
11731173
11741174 const result = createNode ( kind , scanner . getStartPos ( ) ) ;
1175- switch ( kind ) {
1176- case SyntaxKind . Identifier :
1177- ( result as Identifier ) . escapedText = "" as __String ;
1178- break ;
1179- default : // TODO: GH#17346
1180- ( result as LiteralLikeNode ) . text = "" ;
1181- break ;
1175+
1176+ if ( kind === SyntaxKind . Identifier ) {
1177+ ( result as Identifier ) . escapedText = "" as __String ;
11821178 }
1183- return finishNode ( result ) ;
1179+ else if ( isLiteralKind ( kind ) || isTemplateLiteralKind ( kind ) ) {
1180+ ( result as LiteralLikeNode ) . text = "" ;
1181+ }
1182+
1183+ return finishNode ( result ) as T ;
11841184 }
11851185
11861186 function internIdentifier ( text : string ) : string {
@@ -1208,7 +1208,7 @@ namespace ts {
12081208 return finishNode ( node ) ;
12091209 }
12101210
1211- return < Identifier > createMissingNode ( SyntaxKind . Identifier , /*reportAtCurrentPosition*/ false , diagnosticMessage || Diagnostics . Identifier_expected ) ;
1211+ return createMissingNode < Identifier > ( SyntaxKind . Identifier , /*reportAtCurrentPosition*/ false , diagnosticMessage || Diagnostics . Identifier_expected ) ;
12121212 }
12131213
12141214 function parseIdentifier ( diagnosticMessage ?: DiagnosticMessage ) : Identifier {
@@ -2002,7 +2002,7 @@ namespace ts {
20022002 // Report that we need an identifier. However, report it right after the dot,
20032003 // and not on the next token. This is because the next token might actually
20042004 // be an identifier and the error would be quite confusing.
2005- return < Identifier > createMissingNode ( SyntaxKind . Identifier , /*reportAtCurrentPosition*/ true , Diagnostics . Identifier_expected ) ;
2005+ return createMissingNode < Identifier > ( SyntaxKind . Identifier , /*reportAtCurrentPosition*/ true , Diagnostics . Identifier_expected ) ;
20062006 }
20072007 }
20082008
@@ -5534,7 +5534,7 @@ namespace ts {
55345534
55355535 if ( decorators || modifiers ) {
55365536 // treat this as a property declaration with a missing name.
5537- const name = < Identifier > createMissingNode ( SyntaxKind . Identifier , /*reportAtCurrentPosition*/ true , Diagnostics . Declaration_expected ) ;
5537+ const name = createMissingNode < Identifier > ( SyntaxKind . Identifier , /*reportAtCurrentPosition*/ true , Diagnostics . Declaration_expected ) ;
55385538 return parsePropertyDeclaration ( fullStart , decorators , modifiers , name , /*questionToken*/ undefined ) ;
55395539 }
55405540
@@ -6836,7 +6836,7 @@ namespace ts {
68366836 function createJSDocIdentifier ( isIdentifier : boolean , createIfMissing : boolean ) : Identifier {
68376837 if ( ! isIdentifier ) {
68386838 if ( createIfMissing ) {
6839- return < Identifier > createMissingNode ( SyntaxKind . Identifier , /*reportAtCurrentPosition*/ true , Diagnostics . Identifier_expected ) ;
6839+ return createMissingNode < Identifier > ( SyntaxKind . Identifier , /*reportAtCurrentPosition*/ true , Diagnostics . Identifier_expected ) ;
68406840 }
68416841 else {
68426842 parseErrorAtCurrentToken ( Diagnostics . Identifier_expected ) ;
0 commit comments