@@ -1163,7 +1163,7 @@ namespace ts {
1163
1163
return node ;
1164
1164
}
1165
1165
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 {
1167
1167
if ( reportAtCurrentPosition ) {
1168
1168
parseErrorAtPosition ( scanner . getStartPos ( ) , 0 , diagnosticMessage , arg0 ) ;
1169
1169
}
@@ -1172,15 +1172,15 @@ namespace ts {
1172
1172
}
1173
1173
1174
1174
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 ;
1182
1178
}
1183
- return finishNode ( result ) ;
1179
+ else if ( isLiteralKind ( kind ) || isTemplateLiteralKind ( kind ) ) {
1180
+ ( result as LiteralLikeNode ) . text = "" ;
1181
+ }
1182
+
1183
+ return finishNode ( result ) as T ;
1184
1184
}
1185
1185
1186
1186
function internIdentifier ( text : string ) : string {
@@ -1208,7 +1208,7 @@ namespace ts {
1208
1208
return finishNode ( node ) ;
1209
1209
}
1210
1210
1211
- return < Identifier > createMissingNode ( SyntaxKind . Identifier , /*reportAtCurrentPosition*/ false , diagnosticMessage || Diagnostics . Identifier_expected ) ;
1211
+ return createMissingNode < Identifier > ( SyntaxKind . Identifier , /*reportAtCurrentPosition*/ false , diagnosticMessage || Diagnostics . Identifier_expected ) ;
1212
1212
}
1213
1213
1214
1214
function parseIdentifier ( diagnosticMessage ?: DiagnosticMessage ) : Identifier {
@@ -2002,7 +2002,7 @@ namespace ts {
2002
2002
// Report that we need an identifier. However, report it right after the dot,
2003
2003
// and not on the next token. This is because the next token might actually
2004
2004
// 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 ) ;
2006
2006
}
2007
2007
}
2008
2008
@@ -5534,7 +5534,7 @@ namespace ts {
5534
5534
5535
5535
if ( decorators || modifiers ) {
5536
5536
// 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 ) ;
5538
5538
return parsePropertyDeclaration ( fullStart , decorators , modifiers , name , /*questionToken*/ undefined ) ;
5539
5539
}
5540
5540
@@ -6836,7 +6836,7 @@ namespace ts {
6836
6836
function createJSDocIdentifier ( isIdentifier : boolean , createIfMissing : boolean ) : Identifier {
6837
6837
if ( ! isIdentifier ) {
6838
6838
if ( createIfMissing ) {
6839
- return < Identifier > createMissingNode ( SyntaxKind . Identifier , /*reportAtCurrentPosition*/ true , Diagnostics . Identifier_expected ) ;
6839
+ return createMissingNode < Identifier > ( SyntaxKind . Identifier , /*reportAtCurrentPosition*/ true , Diagnostics . Identifier_expected ) ;
6840
6840
}
6841
6841
else {
6842
6842
parseErrorAtCurrentToken ( Diagnostics . Identifier_expected ) ;
0 commit comments