@@ -164,8 +164,8 @@ export class Parser extends DiagnosticEmitter {
164
164
this . skipStatement ( tn ) ;
165
165
continue ;
166
166
}
167
- if ( ! decorators ) decorators = [ ] ;
168
- decorators . push ( decorator ) ;
167
+ if ( ! decorators ) decorators = [ decorator ] ;
168
+ else decorators . push ( decorator ) ;
169
169
}
170
170
171
171
// check modifiers
@@ -454,7 +454,7 @@ export class Parser extends DiagnosticEmitter {
454
454
} else if ( token == Token . IDENTIFIER ) {
455
455
let first = Node . createSimpleTypeName ( tn . readIdentifier ( ) , tn . range ( ) ) ;
456
456
let current = first ;
457
- let parameters = new Array < TypeNode > ( ) ;
457
+ let parameters : TypeNode [ ] | null = null ;
458
458
let nullable = false ;
459
459
460
460
// Identifier ('.' Identifier)+
@@ -477,7 +477,8 @@ export class Parser extends DiagnosticEmitter {
477
477
do {
478
478
let parameter = this . parseType ( tn , true , suppressErrors ) ;
479
479
if ( ! parameter ) return null ;
480
- parameters . push ( < TypeNode > parameter ) ;
480
+ if ( ! parameters ) parameters = [ < TypeNode > parameter ] ;
481
+ else parameters . push ( < TypeNode > parameter ) ;
481
482
} while ( tn . skip ( Token . COMMA ) ) ;
482
483
if ( ! tn . skip ( Token . GREATERTHAN ) ) {
483
484
if ( ! suppressErrors ) {
@@ -503,8 +504,7 @@ export class Parser extends DiagnosticEmitter {
503
504
return null ;
504
505
}
505
506
}
506
- type = Node . createType ( first , parameters , nullable , tn . range ( startPos , tn . pos ) ) ;
507
-
507
+ type = Node . createType ( first , parameters || [ ] , nullable , tn . range ( startPos , tn . pos ) ) ;
508
508
} else {
509
509
if ( ! suppressErrors ) {
510
510
this . error (
@@ -939,7 +939,7 @@ export class Parser extends DiagnosticEmitter {
939
939
940
940
// at '<': TypeParameter (',' TypeParameter)* '>'
941
941
942
- var typeParameters = new Array < TypeParameterNode > ( ) ;
942
+ var typeParameters : TypeParameterNode [ ] | null = null ;
943
943
var seenOptional = false ;
944
944
while ( ! tn . skip ( Token . GREATERTHAN ) ) {
945
945
let typeParameter = this . parseTypeParameter ( tn ) ;
@@ -953,7 +953,8 @@ export class Parser extends DiagnosticEmitter {
953
953
) ;
954
954
typeParameter . defaultType = null ;
955
955
}
956
- typeParameters . push ( < TypeParameterNode > typeParameter ) ;
956
+ if ( ! typeParameters ) typeParameters = [ typeParameter ] ;
957
+ else typeParameters . push ( typeParameter ) ;
957
958
if ( ! tn . skip ( Token . COMMA ) ) {
958
959
if ( tn . skip ( Token . GREATERTHAN ) ) {
959
960
break ;
@@ -966,7 +967,7 @@ export class Parser extends DiagnosticEmitter {
966
967
}
967
968
}
968
969
}
969
- if ( typeParameters . length === 0 ) {
970
+ if ( ! ( typeParameters && typeParameters . length ) ) {
970
971
this . error (
971
972
DiagnosticCode . Type_parameter_list_cannot_be_empty ,
972
973
tn . range ( )
@@ -1532,8 +1533,8 @@ export class Parser extends DiagnosticEmitter {
1532
1533
let type = this . parseType ( tn ) ;
1533
1534
if ( ! type ) return null ;
1534
1535
if ( ! isInterface ) {
1535
- if ( ! implementsTypes ) implementsTypes = [ ] ;
1536
- implementsTypes . push ( < TypeNode > type ) ;
1536
+ if ( ! implementsTypes ) implementsTypes = [ < TypeNode > type ] ;
1537
+ else implementsTypes . push ( < TypeNode > type ) ;
1537
1538
}
1538
1539
} while ( tn . skip ( Token . COMMA ) ) ;
1539
1540
}
@@ -1636,14 +1637,15 @@ export class Parser extends DiagnosticEmitter {
1636
1637
var startPos = tn . pos ;
1637
1638
var isInterface = parent . kind == NodeKind . INTERFACEDECLARATION ;
1638
1639
1639
- var decorators = new Array < DecoratorNode > ( ) ;
1640
+ var decorators : DecoratorNode [ ] | null = null ;
1640
1641
if ( tn . skip ( Token . AT ) ) {
1641
1642
do {
1642
1643
let decorator = this . parseDecorator ( tn ) ;
1643
1644
if ( ! decorator ) break ;
1644
- decorators . push ( < DecoratorNode > decorator ) ;
1645
+ if ( ! decorators ) decorators = [ < DecoratorNode > decorator ] ;
1646
+ else decorators . push ( < DecoratorNode > decorator ) ;
1645
1647
} while ( tn . skip ( Token . AT ) ) ;
1646
- if ( isInterface ) {
1648
+ if ( decorators && isInterface ) {
1647
1649
this . error (
1648
1650
DiagnosticCode . Decorators_are_not_valid_here ,
1649
1651
Range . join ( decorators [ 0 ] . range , decorators [ decorators . length - 1 ] . range )
@@ -2064,11 +2066,11 @@ export class Parser extends DiagnosticEmitter {
2064
2066
return null ;
2065
2067
}
2066
2068
2067
- parseIndexSignatureDeclaration ( tn : Tokenizer , decorators : DecoratorNode [ ] ) : IndexSignatureDeclaration | null {
2069
+ parseIndexSignatureDeclaration ( tn : Tokenizer , decorators : DecoratorNode [ ] | null ) : IndexSignatureDeclaration | null {
2068
2070
2069
2071
// at: '[': 'key' ':' Type ']' ':' Type
2070
2072
2071
- if ( decorators . length ) {
2073
+ if ( decorators && decorators . length ) {
2072
2074
this . error (
2073
2075
DiagnosticCode . Decorators_are_not_valid_here ,
2074
2076
Range . join ( decorators [ 0 ] . range , decorators [ decorators . length - 1 ] . range )
@@ -3410,7 +3412,7 @@ export class Parser extends DiagnosticEmitter {
3410
3412
3411
3413
var state = tn . mark ( ) ;
3412
3414
if ( ! tn . skip ( Token . LESSTHAN ) ) return null ;
3413
- var typeArguments = new Array < CommonTypeNode > ( ) ;
3415
+ var typeArguments : CommonTypeNode [ ] | null = null ;
3414
3416
do {
3415
3417
if ( tn . peek ( ) === Token . GREATERTHAN ) {
3416
3418
break ;
@@ -3420,7 +3422,8 @@ export class Parser extends DiagnosticEmitter {
3420
3422
tn . reset ( state ) ;
3421
3423
return null ;
3422
3424
}
3423
- typeArguments . push ( type ) ;
3425
+ if ( ! typeArguments ) typeArguments = [ type ] ;
3426
+ else typeArguments . push ( type ) ;
3424
3427
} while ( tn . skip ( Token . COMMA ) ) ;
3425
3428
if ( tn . skip ( Token . GREATERTHAN ) && tn . skip ( Token . OPENPAREN ) ) {
3426
3429
return typeArguments ;
0 commit comments