@@ -439,7 +439,8 @@ namespace ts {
439439 // during global merging in the checker. Why? The only case when ambient module is permitted inside another module is module augmentation
440440 // and this case is specially handled. Module augmentations should only be merged with original module definition
441441 // and should never be merged directly with other augmentation, and the latter case would be possible if automatic merge is allowed.
442- const isJSDocTypedefInJSDocNamespace = isInJavaScriptFile ( node ) && node . kind === SyntaxKind . JSDocTypedefTag &&
442+ if ( node . kind === SyntaxKind . JSDocTypedefTag ) Debug . assert ( isInJavaScriptFile ( node ) ) ; // We shouldn't add symbols for JSDoc nodes if not in a JS file.
443+ const isJSDocTypedefInJSDocNamespace = node . kind === SyntaxKind . JSDocTypedefTag &&
443444 ( node as JSDocTypedefTag ) . name &&
444445 ( node as JSDocTypedefTag ) . name . kind === SyntaxKind . Identifier &&
445446 ( ( node as JSDocTypedefTag ) . name as Identifier ) . isInJSDocNamespace ;
@@ -603,9 +604,7 @@ namespace ts {
603604 // Binding of JsDocComment should be done before the current block scope container changes.
604605 // because the scope of JsDocComment should not be affected by whether the current node is a
605606 // container or not.
606- if ( node . jsDoc ) {
607- forEach ( node . jsDoc , bind ) ;
608- }
607+ forEach ( node . jsDoc , bind ) ;
609608 if ( checkUnreachable ( node ) ) {
610609 bindEachChild ( node ) ;
611610 return ;
@@ -2071,10 +2070,7 @@ namespace ts {
20712070 return bindVariableDeclarationOrBindingElement ( < VariableDeclaration | BindingElement > node ) ;
20722071 case SyntaxKind . PropertyDeclaration :
20732072 case SyntaxKind . PropertySignature :
2074- case SyntaxKind . JSDocRecordMember :
2075- return bindPropertyOrMethodOrAccessor ( < Declaration > node , SymbolFlags . Property | ( ( < PropertyDeclaration > node ) . questionToken ? SymbolFlags . Optional : SymbolFlags . None ) , SymbolFlags . PropertyExcludes ) ;
2076- case SyntaxKind . JSDocPropertyTag :
2077- return bindJSDocProperty ( < JSDocPropertyTag > node ) ;
2073+ return bindPropertyWorker ( node as PropertyDeclaration | PropertySignature ) ;
20782074 case SyntaxKind . PropertyAssignment :
20792075 case SyntaxKind . ShorthandPropertyAssignment :
20802076 return bindPropertyOrMethodOrAccessor ( < Declaration > node , SymbolFlags . Property , SymbolFlags . PropertyExcludes ) ;
@@ -2119,13 +2115,10 @@ namespace ts {
21192115 return bindPropertyOrMethodOrAccessor ( < Declaration > node , SymbolFlags . SetAccessor , SymbolFlags . SetAccessorExcludes ) ;
21202116 case SyntaxKind . FunctionType :
21212117 case SyntaxKind . ConstructorType :
2122- case SyntaxKind . JSDocFunctionType :
21232118 return bindFunctionOrConstructorType ( < SignatureDeclaration > node ) ;
21242119 case SyntaxKind . TypeLiteral :
21252120 case SyntaxKind . MappedType :
2126- case SyntaxKind . JSDocTypeLiteral :
2127- case SyntaxKind . JSDocRecordType :
2128- return bindAnonymousDeclaration ( < Declaration > node , SymbolFlags . TypeLiteral , "__type" ) ;
2121+ return bindAnonymousTypeWorker ( node as TypeLiteralNode | MappedTypeNode ) ;
21292122 case SyntaxKind . ObjectLiteralExpression :
21302123 return bindObjectLiteralExpression ( < ObjectLiteralExpression > node ) ;
21312124 case SyntaxKind . FunctionExpression :
@@ -2146,11 +2139,6 @@ namespace ts {
21462139 return bindClassLikeDeclaration ( < ClassLikeDeclaration > node ) ;
21472140 case SyntaxKind . InterfaceDeclaration :
21482141 return bindBlockScopedDeclaration ( < Declaration > node , SymbolFlags . Interface , SymbolFlags . InterfaceExcludes ) ;
2149- case SyntaxKind . JSDocTypedefTag :
2150- if ( isInJavaScriptFile ( node ) && ( ! ( < JSDocTypedefTag > node ) . fullName || ( < JSDocTypedefTag > node ) . fullName . kind === SyntaxKind . Identifier ) ) {
2151- return bindBlockScopedDeclaration ( < Declaration > node , SymbolFlags . TypeAlias , SymbolFlags . TypeAliasExcludes ) ;
2152- }
2153- break ;
21542142 case SyntaxKind . TypeAliasDeclaration :
21552143 return bindBlockScopedDeclaration ( < Declaration > node , SymbolFlags . TypeAlias , SymbolFlags . TypeAliasExcludes ) ;
21562144 case SyntaxKind . EnumDeclaration :
@@ -2188,9 +2176,41 @@ namespace ts {
21882176 // falls through
21892177 case SyntaxKind . ModuleBlock :
21902178 return updateStrictModeStatementList ( ( < Block | ModuleBlock > node ) . statements ) ;
2179+
2180+ default :
2181+ if ( isInJavaScriptFile ( node ) ) return bindJSDocWorker ( node ) ;
2182+ }
2183+ }
2184+
2185+ function bindJSDocWorker ( node : Node ) {
2186+ switch ( node . kind ) {
2187+ case SyntaxKind . JSDocRecordMember :
2188+ return bindPropertyWorker ( node as JSDocRecordMember ) ;
2189+ case SyntaxKind . JSDocPropertyTag :
2190+ return declareSymbolAndAddToSymbolTable ( node as JSDocPropertyTag , SymbolFlags . Property , SymbolFlags . PropertyExcludes ) ;
2191+ case SyntaxKind . JSDocFunctionType :
2192+ return bindFunctionOrConstructorType ( < SignatureDeclaration > node ) ;
2193+ case SyntaxKind . JSDocTypeLiteral :
2194+ case SyntaxKind . JSDocRecordType :
2195+ return bindAnonymousTypeWorker ( node as JSDocTypeLiteral | JSDocRecordType ) ;
2196+ case SyntaxKind . JSDocTypedefTag : {
2197+ const { fullName } = node as JSDocTypedefTag ;
2198+ if ( ! fullName || fullName . kind === SyntaxKind . Identifier ) {
2199+ return bindBlockScopedDeclaration ( < Declaration > node , SymbolFlags . TypeAlias , SymbolFlags . TypeAliasExcludes ) ;
2200+ }
2201+ break ;
2202+ }
21912203 }
21922204 }
21932205
2206+ function bindPropertyWorker ( node : PropertyDeclaration | PropertySignature ) {
2207+ return bindPropertyOrMethodOrAccessor ( node , SymbolFlags . Property | ( node . questionToken ? SymbolFlags . Optional : SymbolFlags . None ) , SymbolFlags . PropertyExcludes ) ;
2208+ }
2209+
2210+ function bindAnonymousTypeWorker ( node : TypeLiteralNode | MappedTypeNode | JSDocTypeLiteral | JSDocRecordType ) {
2211+ return bindAnonymousDeclaration ( < Declaration > node , SymbolFlags . TypeLiteral , "__type" ) ;
2212+ }
2213+
21942214 function checkTypePredicate ( node : TypePredicateNode ) {
21952215 const { parameterName, type } = node ;
21962216 if ( parameterName && parameterName . kind === SyntaxKind . Identifier ) {
@@ -2556,10 +2576,8 @@ namespace ts {
25562576 }
25572577
25582578 function bindPropertyOrMethodOrAccessor ( node : Declaration , symbolFlags : SymbolFlags , symbolExcludes : SymbolFlags ) {
2559- if ( ! isDeclarationFile ( file ) && ! isInAmbientContext ( node ) ) {
2560- if ( isAsyncFunction ( node ) ) {
2561- emitFlags |= NodeFlags . HasAsyncFunctions ;
2562- }
2579+ if ( ! isDeclarationFile ( file ) && ! isInAmbientContext ( node ) && isAsyncFunction ( node ) ) {
2580+ emitFlags |= NodeFlags . HasAsyncFunctions ;
25632581 }
25642582
25652583 if ( currentFlow && isObjectLiteralOrClassExpressionMethod ( node ) ) {
@@ -2571,10 +2589,6 @@ namespace ts {
25712589 : declareSymbolAndAddToSymbolTable ( node , symbolFlags , symbolExcludes ) ;
25722590 }
25732591
2574- function bindJSDocProperty ( node : JSDocPropertyTag ) {
2575- return declareSymbolAndAddToSymbolTable ( node , SymbolFlags . Property , SymbolFlags . PropertyExcludes ) ;
2576- }
2577-
25782592 // reachability checks
25792593
25802594 function shouldReportErrorOnModuleDeclaration ( node : ModuleDeclaration ) : boolean {
0 commit comments