@@ -445,19 +445,17 @@ namespace ts {
445445 case SyntaxKind . JsxClosingElement :
446446 return visitNode ( cbNode , ( < JsxClosingElement > node ) . tagName ) ;
447447
448+ case SyntaxKind . OptionalType :
449+ case SyntaxKind . RestType :
448450 case SyntaxKind . JSDocTypeExpression :
449- return visitNode ( cbNode , ( < JSDocTypeExpression > node ) . type ) ;
450451 case SyntaxKind . JSDocNonNullableType :
451- return visitNode ( cbNode , ( < JSDocNonNullableType > node ) . type ) ;
452452 case SyntaxKind . JSDocNullableType :
453- return visitNode ( cbNode , ( < JSDocNullableType > node ) . type ) ;
454453 case SyntaxKind . JSDocOptionalType :
455- return visitNode ( cbNode , ( < JSDocOptionalType > node ) . type ) ;
454+ case SyntaxKind . JSDocVariadicType :
455+ return visitNode ( cbNode , ( < OptionalTypeNode | RestTypeNode | JSDocTypeExpression | JSDocTypeReferencingNode > node ) . type ) ;
456456 case SyntaxKind . JSDocFunctionType :
457457 return visitNodes ( cbNode , cbNodes , ( < JSDocFunctionType > node ) . parameters ) ||
458458 visitNode ( cbNode , ( < JSDocFunctionType > node ) . type ) ;
459- case SyntaxKind . JSDocVariadicType :
460- return visitNode ( cbNode , ( < JSDocVariadicType > node ) . type ) ;
461459 case SyntaxKind . JSDocComment :
462460 return visitNodes ( cbNode , cbNodes , ( < JSDoc > node ) . tags ) ;
463461 case SyntaxKind . JSDocParameterTag :
@@ -2289,7 +2287,7 @@ namespace ts {
22892287 function parseJSDocAllType ( postFixEquals : boolean ) : JSDocAllType | JSDocOptionalType {
22902288 const result = createNode ( SyntaxKind . JSDocAllType ) as JSDocAllType ;
22912289 if ( postFixEquals ) {
2292- return createJSDocPostfixType ( SyntaxKind . JSDocOptionalType , result ) as JSDocOptionalType ;
2290+ return createPostfixType ( SyntaxKind . JSDocOptionalType , result ) as JSDocOptionalType ;
22932291 }
22942292 else {
22952293 nextToken ( ) ;
@@ -2367,7 +2365,7 @@ namespace ts {
23672365 type = finishNode ( variadic ) ;
23682366 }
23692367 if ( token ( ) === SyntaxKind . EqualsToken ) {
2370- return createJSDocPostfixType ( SyntaxKind . JSDocOptionalType , type ) ;
2368+ return createPostfixType ( SyntaxKind . JSDocOptionalType , type ) ;
23712369 }
23722370 return type ;
23732371 }
@@ -2775,9 +2773,23 @@ namespace ts {
27752773 return finishNode ( node ) ;
27762774 }
27772775
2776+ function parseTupleElementType ( ) {
2777+ const pos = getNodePos ( ) ;
2778+ if ( parseOptional ( SyntaxKind . DotDotDotToken ) ) {
2779+ const node = < RestTypeNode > createNode ( SyntaxKind . RestType , pos ) ;
2780+ node . type = parseType ( ) ;
2781+ return finishNode ( node ) ;
2782+ }
2783+ const type = parseType ( ) ;
2784+ if ( ! ( contextFlags & NodeFlags . JSDoc ) && type . kind === SyntaxKind . JSDocNullableType && type . pos === ( < JSDocNullableType > type ) . type . pos ) {
2785+ type . kind = SyntaxKind . OptionalType ;
2786+ }
2787+ return type ;
2788+ }
2789+
27782790 function parseTupleType ( ) : TupleTypeNode {
27792791 const node = < TupleTypeNode > createNode ( SyntaxKind . TupleType ) ;
2780- node . elementTypes = parseBracketedList ( ParsingContext . TupleElementTypes , parseType , SyntaxKind . OpenBracketToken , SyntaxKind . CloseBracketToken ) ;
2792+ node . elementTypes = parseBracketedList ( ParsingContext . TupleElementTypes , parseTupleElementType , SyntaxKind . OpenBracketToken , SyntaxKind . CloseBracketToken ) ;
27812793 return finishNode ( node ) ;
27822794 }
27832795
@@ -2960,14 +2972,14 @@ namespace ts {
29602972 while ( ! scanner . hasPrecedingLineBreak ( ) ) {
29612973 switch ( token ( ) ) {
29622974 case SyntaxKind . ExclamationToken :
2963- type = createJSDocPostfixType ( SyntaxKind . JSDocNonNullableType , type ) ;
2975+ type = createPostfixType ( SyntaxKind . JSDocNonNullableType , type ) ;
29642976 break ;
29652977 case SyntaxKind . QuestionToken :
29662978 // If not in JSDoc and next token is start of a type we have a conditional type
29672979 if ( ! ( contextFlags & NodeFlags . JSDoc ) && lookAhead ( nextTokenIsStartOfType ) ) {
29682980 return type ;
29692981 }
2970- type = createJSDocPostfixType ( SyntaxKind . JSDocNullableType , type ) ;
2982+ type = createPostfixType ( SyntaxKind . JSDocNullableType , type ) ;
29712983 break ;
29722984 case SyntaxKind . OpenBracketToken :
29732985 parseExpected ( SyntaxKind . OpenBracketToken ) ;
@@ -2992,9 +3004,9 @@ namespace ts {
29923004 return type ;
29933005 }
29943006
2995- function createJSDocPostfixType ( kind : SyntaxKind , type : TypeNode ) {
3007+ function createPostfixType ( kind : SyntaxKind , type : TypeNode ) {
29963008 nextToken ( ) ;
2997- const postfix = createNode ( kind , type . pos ) as JSDocOptionalType | JSDocNonNullableType | JSDocNullableType ;
3009+ const postfix = createNode ( kind , type . pos ) as OptionalTypeNode | JSDocOptionalType | JSDocNonNullableType | JSDocNullableType ;
29983010 postfix . type = type ;
29993011 return finishNode ( postfix ) ;
30003012 }
0 commit comments