@@ -1922,7 +1922,6 @@ namespace ts {
19221922 return createMissingList < T > ( ) ;
19231923 }
19241924
1925- // The allowReservedWords parameter controls whether reserved words are permitted after the first dot
19261925 function parseEntityName ( allowReservedWords : boolean , diagnosticMessage ?: DiagnosticMessage ) : EntityName {
19271926 let entity : EntityName = allowReservedWords ? parseIdentifierName ( ) : parseIdentifier ( diagnosticMessage ) ;
19281927 let dotPos = scanner . getStartPos ( ) ;
@@ -1932,6 +1931,7 @@ namespace ts {
19321931 entity . jsdocDotPos = dotPos ;
19331932 break ;
19341933 }
1934+ dotPos = scanner . getStartPos ( ) ;
19351935 const node : QualifiedName = < QualifiedName > createNode ( SyntaxKind . QualifiedName , entity . pos ) ;
19361936 node . left = entity ;
19371937 node . right = parseRightSideOfDot ( allowReservedWords ) ;
@@ -2140,7 +2140,7 @@ namespace ts {
21402140 return finishNode ( parameter ) ;
21412141 }
21422142
2143- function parseJSDocNodeWithType ( kind : SyntaxKind ) : TypeNode {
2143+ function parseJSDocNodeWithType ( kind : SyntaxKind . JSDocVariadicType | SyntaxKind . JSDocNonNullableType ) : TypeNode {
21442144 const result = createNode ( kind ) as JSDocVariadicType | JSDocNonNullableType ;
21452145 nextToken ( ) ;
21462146 result . type = parseType ( ) ;
@@ -2689,27 +2689,30 @@ namespace ts {
26892689 }
26902690
26912691 function parseJSDocPostfixTypeOrHigher ( ) : TypeNode {
2692- let type = parseArrayTypeOrHigher ( ) ;
2693- let postfix : JSDocOptionalType | JSDocNonNullableType | JSDocNullableType ;
2694- // only parse postfix = inside jsdoc, because it's ambiguous elsewhere
2695- if ( contextFlags & NodeFlags . JSDoc && parseOptional ( SyntaxKind . EqualsToken ) ) {
2696- postfix = createNode ( SyntaxKind . JSDocOptionalType , type . pos ) as JSDocOptionalType ;
2697- }
2698- else if ( parseOptional ( SyntaxKind . ExclamationToken ) ) {
2699- postfix = createNode ( SyntaxKind . JSDocNonNullableType , type . pos ) as JSDocNonNullableType ;
2700- }
2701- else if ( parseOptional ( SyntaxKind . QuestionToken ) ) {
2702- postfix = createNode ( SyntaxKind . JSDocNullableType , type . pos ) as JSDocNullableType ;
2703- }
2704- if ( postfix ) {
2705- postfix . type = type ;
2706- type = finishNode ( postfix ) ;
2692+ const type = parseNonArrayType ( ) ;
2693+ const kind = getKind ( token ( ) ) ;
2694+ if ( ! kind ) return type ;
2695+ nextToken ( ) ;
2696+
2697+ const postfix = createNode ( kind , type . pos ) as JSDocOptionalType | JSDocNonNullableType | JSDocNullableType ;
2698+ postfix . type = type ;
2699+ return finishNode ( postfix ) ;
2700+
2701+ function getKind ( tokenKind : SyntaxKind ) : SyntaxKind | undefined {
2702+ switch ( tokenKind ) {
2703+ case SyntaxKind . EqualsToken :
2704+ // only parse postfix = inside jsdoc, because it's ambiguous elsewhere
2705+ return contextFlags & NodeFlags . JSDoc ? SyntaxKind . JSDocOptionalType : undefined ;
2706+ case SyntaxKind . ExclamationToken :
2707+ return SyntaxKind . JSDocNonNullableType ;
2708+ case SyntaxKind . QuestionToken :
2709+ return SyntaxKind . JSDocNullableType ;
2710+ }
27072711 }
2708- return type ;
27092712 }
27102713
27112714 function parseArrayTypeOrHigher ( ) : TypeNode {
2712- let type = parseNonArrayType ( ) ;
2715+ let type = parseJSDocPostfixTypeOrHigher ( ) ;
27132716 while ( ! scanner . hasPrecedingLineBreak ( ) && parseOptional ( SyntaxKind . OpenBracketToken ) ) {
27142717 if ( isStartOfType ( ) ) {
27152718 const node = < IndexedAccessTypeNode > createNode ( SyntaxKind . IndexedAccessType , type . pos ) ;
@@ -2741,7 +2744,7 @@ namespace ts {
27412744 case SyntaxKind . KeyOfKeyword :
27422745 return parseTypeOperator ( SyntaxKind . KeyOfKeyword ) ;
27432746 }
2744- return parseJSDocPostfixTypeOrHigher ( ) ;
2747+ return parseArrayTypeOrHigher ( ) ;
27452748 }
27462749
27472750 function parseUnionOrIntersectionType ( kind : SyntaxKind . UnionType | SyntaxKind . IntersectionType , parseConstituentType : ( ) => TypeNode , operator : SyntaxKind . BarToken | SyntaxKind . AmpersandToken ) : TypeNode {
@@ -6576,15 +6579,8 @@ namespace ts {
65766579 return finishNode ( typedefTag ) ;
65776580
65786581 function isObjectTypeReference ( node : TypeNode ) {
6579- if ( node . kind === SyntaxKind . ObjectKeyword ) {
6580- return true ;
6581- }
6582- if ( node . kind === SyntaxKind . TypeReference ) {
6583- const jsDocTypeReference = < TypeReferenceNode > node ;
6584- if ( jsDocTypeReference . typeName . kind === SyntaxKind . Identifier ) {
6585- return ( jsDocTypeReference . typeName as Identifier ) . text === "Object" ;
6586- }
6587- }
6582+ return node . kind === SyntaxKind . ObjectKeyword ||
6583+ isTypeReferenceNode ( node ) && ts . isIdentifier ( node . typeName ) && node . typeName . text === "Object" ;
65886584 }
65896585
65906586 function scanChildTags ( ) : JSDocTypeLiteral {
0 commit comments