@@ -439,7 +439,8 @@ namespace ts {
439
439
// during global merging in the checker. Why? The only case when ambient module is permitted inside another module is module augmentation
440
440
// and this case is specially handled. Module augmentations should only be merged with original module definition
441
441
// 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 &&
443
444
( node as JSDocTypedefTag ) . name &&
444
445
( node as JSDocTypedefTag ) . name . kind === SyntaxKind . Identifier &&
445
446
( ( node as JSDocTypedefTag ) . name as Identifier ) . isInJSDocNamespace ;
@@ -603,9 +604,7 @@ namespace ts {
603
604
// Binding of JsDocComment should be done before the current block scope container changes.
604
605
// because the scope of JsDocComment should not be affected by whether the current node is a
605
606
// container or not.
606
- if ( node . jsDoc ) {
607
- forEach ( node . jsDoc , bind ) ;
608
- }
607
+ forEach ( node . jsDoc , bind ) ;
609
608
if ( checkUnreachable ( node ) ) {
610
609
bindEachChild ( node ) ;
611
610
return ;
@@ -2071,10 +2070,7 @@ namespace ts {
2071
2070
return bindVariableDeclarationOrBindingElement ( < VariableDeclaration | BindingElement > node ) ;
2072
2071
case SyntaxKind . PropertyDeclaration :
2073
2072
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 ) ;
2078
2074
case SyntaxKind . PropertyAssignment :
2079
2075
case SyntaxKind . ShorthandPropertyAssignment :
2080
2076
return bindPropertyOrMethodOrAccessor ( < Declaration > node , SymbolFlags . Property , SymbolFlags . PropertyExcludes ) ;
@@ -2119,13 +2115,10 @@ namespace ts {
2119
2115
return bindPropertyOrMethodOrAccessor ( < Declaration > node , SymbolFlags . SetAccessor , SymbolFlags . SetAccessorExcludes ) ;
2120
2116
case SyntaxKind . FunctionType :
2121
2117
case SyntaxKind . ConstructorType :
2122
- case SyntaxKind . JSDocFunctionType :
2123
2118
return bindFunctionOrConstructorType ( < SignatureDeclaration > node ) ;
2124
2119
case SyntaxKind . TypeLiteral :
2125
2120
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 ) ;
2129
2122
case SyntaxKind . ObjectLiteralExpression :
2130
2123
return bindObjectLiteralExpression ( < ObjectLiteralExpression > node ) ;
2131
2124
case SyntaxKind . FunctionExpression :
@@ -2146,11 +2139,6 @@ namespace ts {
2146
2139
return bindClassLikeDeclaration ( < ClassLikeDeclaration > node ) ;
2147
2140
case SyntaxKind . InterfaceDeclaration :
2148
2141
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 ;
2154
2142
case SyntaxKind . TypeAliasDeclaration :
2155
2143
return bindBlockScopedDeclaration ( < Declaration > node , SymbolFlags . TypeAlias , SymbolFlags . TypeAliasExcludes ) ;
2156
2144
case SyntaxKind . EnumDeclaration :
@@ -2188,9 +2176,41 @@ namespace ts {
2188
2176
// falls through
2189
2177
case SyntaxKind . ModuleBlock :
2190
2178
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
+ }
2191
2203
}
2192
2204
}
2193
2205
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
+
2194
2214
function checkTypePredicate ( node : TypePredicateNode ) {
2195
2215
const { parameterName, type } = node ;
2196
2216
if ( parameterName && parameterName . kind === SyntaxKind . Identifier ) {
@@ -2556,10 +2576,8 @@ namespace ts {
2556
2576
}
2557
2577
2558
2578
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 ;
2563
2581
}
2564
2582
2565
2583
if ( currentFlow && isObjectLiteralOrClassExpressionMethod ( node ) ) {
@@ -2571,10 +2589,6 @@ namespace ts {
2571
2589
: declareSymbolAndAddToSymbolTable ( node , symbolFlags , symbolExcludes ) ;
2572
2590
}
2573
2591
2574
- function bindJSDocProperty ( node : JSDocPropertyTag ) {
2575
- return declareSymbolAndAddToSymbolTable ( node , SymbolFlags . Property , SymbolFlags . PropertyExcludes ) ;
2576
- }
2577
-
2578
2592
// reachability checks
2579
2593
2580
2594
function shouldReportErrorOnModuleDeclaration ( node : ModuleDeclaration ) : boolean {
0 commit comments