@@ -2739,50 +2739,50 @@ namespace ts {
2739
2739
return token ( ) === SyntaxKind . CloseParenToken || isStartOfParameter ( ) || isStartOfType ( ) ;
2740
2740
}
2741
2741
2742
- function parseJSDocPostfixTypeOrHigher ( ) : TypeNode {
2742
+ function parsePostfixTypeOrHigher ( ) : TypeNode {
2743
2743
let kind : SyntaxKind | undefined ;
2744
2744
let type = parseNonArrayType ( ) ;
2745
- while ( kind = getKind ( token ( ) ) ) {
2746
- nextToken ( ) ;
2747
- const postfix = createNode ( kind , type . pos ) as JSDocOptionalType | JSDocNonNullableType | JSDocNullableType ;
2748
- postfix . type = type ;
2749
- type = finishNode ( postfix ) ;
2750
- }
2751
- return type ;
2752
-
2753
- function getKind ( tokenKind : SyntaxKind ) : SyntaxKind | undefined {
2754
- switch ( tokenKind ) {
2755
- case SyntaxKind . EqualsToken :
2756
- // only parse postfix = inside jsdoc, because it's ambiguous elsewhere
2757
- return contextFlags & NodeFlags . JSDoc ? SyntaxKind . JSDocOptionalType : undefined ;
2758
- case SyntaxKind . ExclamationToken :
2759
- return SyntaxKind . JSDocNonNullableType ;
2760
- case SyntaxKind . QuestionToken :
2761
- return SyntaxKind . JSDocNullableType ;
2762
- }
2763
- }
2764
- }
2765
-
2766
- function parseArrayTypeOrHigher ( ) : TypeNode {
2767
- let type = parseJSDocPostfixTypeOrHigher ( ) ;
2768
- while ( ! scanner . hasPrecedingLineBreak ( ) && parseOptional ( SyntaxKind . OpenBracketToken ) ) {
2769
- if ( isStartOfType ( ) ) {
2770
- const node = < IndexedAccessTypeNode > createNode ( SyntaxKind . IndexedAccessType , type . pos ) ;
2771
- node . objectType = type ;
2772
- node . indexType = parseType ( ) ;
2773
- parseExpected ( SyntaxKind . CloseBracketToken ) ;
2774
- type = finishNode ( node ) ;
2745
+ while ( ! scanner . hasPrecedingLineBreak ( ) && ( kind = getPostfixTypeKind ( token ( ) ) ) ) {
2746
+ if ( kind === SyntaxKind . ArrayType ) {
2747
+ parseExpected ( SyntaxKind . OpenBracketToken ) ;
2748
+ if ( isStartOfType ( ) ) {
2749
+ const node = createNode ( SyntaxKind . IndexedAccessType , type . pos ) as IndexedAccessTypeNode ;
2750
+ node . objectType = type ;
2751
+ node . indexType = parseType ( ) ;
2752
+ parseExpected ( SyntaxKind . CloseBracketToken ) ;
2753
+ type = finishNode ( node ) ;
2754
+ }
2755
+ else {
2756
+ const node = createNode ( SyntaxKind . ArrayType , type . pos ) as ArrayTypeNode ;
2757
+ node . elementType = type ;
2758
+ parseExpected ( SyntaxKind . CloseBracketToken ) ;
2759
+ type = finishNode ( node ) ;
2760
+ }
2775
2761
}
2776
2762
else {
2777
- const node = < ArrayTypeNode > createNode ( SyntaxKind . ArrayType , type . pos ) ;
2778
- node . elementType = type ;
2779
- parseExpected ( SyntaxKind . CloseBracketToken ) ;
2780
- type = finishNode ( node ) ;
2763
+ nextToken ( ) ;
2764
+ const postfix = createNode ( kind , type . pos ) as JSDocOptionalType | JSDocNonNullableType | JSDocNullableType ;
2765
+ postfix . type = type ;
2766
+ type = finishNode ( postfix ) ;
2781
2767
}
2782
2768
}
2783
2769
return type ;
2784
2770
}
2785
2771
2772
+ function getPostfixTypeKind ( tokenKind : SyntaxKind ) : SyntaxKind | undefined {
2773
+ switch ( tokenKind ) {
2774
+ case SyntaxKind . EqualsToken :
2775
+ // only parse postfix = inside jsdoc, because it's ambiguous elsewhere
2776
+ return contextFlags & NodeFlags . JSDoc ? SyntaxKind . JSDocOptionalType : undefined ;
2777
+ case SyntaxKind . ExclamationToken :
2778
+ return SyntaxKind . JSDocNonNullableType ;
2779
+ case SyntaxKind . QuestionToken :
2780
+ return SyntaxKind . JSDocNullableType ;
2781
+ case SyntaxKind . OpenBracketToken :
2782
+ return SyntaxKind . ArrayType ;
2783
+ }
2784
+ }
2785
+
2786
2786
function parseTypeOperator ( operator : SyntaxKind . KeyOfKeyword ) {
2787
2787
const node = < TypeOperatorNode > createNode ( SyntaxKind . TypeOperator ) ;
2788
2788
parseExpected ( operator ) ;
@@ -2796,7 +2796,7 @@ namespace ts {
2796
2796
case SyntaxKind . KeyOfKeyword :
2797
2797
return parseTypeOperator ( SyntaxKind . KeyOfKeyword ) ;
2798
2798
}
2799
- return parseArrayTypeOrHigher ( ) ;
2799
+ return parsePostfixTypeOrHigher ( ) ;
2800
2800
}
2801
2801
2802
2802
function parseUnionOrIntersectionType ( kind : SyntaxKind . UnionType | SyntaxKind . IntersectionType , parseConstituentType : ( ) => TypeNode , operator : SyntaxKind . BarToken | SyntaxKind . AmpersandToken ) : TypeNode {
0 commit comments