@@ -439,6 +439,7 @@ 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
+ if ( node . kind === SyntaxKind . JSDocTypedefTag ) Debug . assert ( isInJavaScriptFile ( node ) ) ; // We shouldn't add symbols for JSDoc nodes if not in a JS file.
442
443
const isJSDocTypedefInJSDocNamespace = node . kind === SyntaxKind . JSDocTypedefTag &&
443
444
( node as JSDocTypedefTag ) . name &&
444
445
( node as JSDocTypedefTag ) . name . kind === SyntaxKind . Identifier &&
@@ -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 ( isInJavaScriptFile ( node ) && 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 ;
@@ -1913,9 +1912,7 @@ namespace ts {
1913
1912
// Here the current node is "foo", which is a container, but the scope of "MyType" should
1914
1913
// not be inside "foo". Therefore we always bind @typedef before bind the parent node,
1915
1914
// and skip binding this tag later when binding all the other jsdoc tags.
1916
- if ( isInJavaScriptFile ( node ) ) {
1917
- bindJSDocTypedefTagIfAny ( node ) ;
1918
- }
1915
+ bindJSDocTypedefTagIfAny ( node ) ;
1919
1916
1920
1917
// First we bind declaration nodes to a symbol if possible. We'll both create a symbol
1921
1918
// and then potentially add the symbol to an appropriate symbol table. Possible
@@ -2003,7 +2000,7 @@ namespace ts {
2003
2000
// for typedef type names with namespaces, bind the new jsdoc type symbol here
2004
2001
// because it requires all containing namespaces to be in effect, namely the
2005
2002
// current "blockScopeContainer" needs to be set to its immediate namespace parent.
2006
- if ( ( < Identifier > node ) . isInJSDocNamespace ) {
2003
+ if ( isInJavaScriptFile ( node ) && ( < Identifier > node ) . isInJSDocNamespace ) {
2007
2004
let parentNode = node . parent ;
2008
2005
while ( parentNode && parentNode . kind !== SyntaxKind . JSDocTypedefTag ) {
2009
2006
parentNode = parentNode . parent ;
@@ -2073,10 +2070,7 @@ namespace ts {
2073
2070
return bindVariableDeclarationOrBindingElement ( < VariableDeclaration | BindingElement > node ) ;
2074
2071
case SyntaxKind . PropertyDeclaration :
2075
2072
case SyntaxKind . PropertySignature :
2076
- case SyntaxKind . JSDocRecordMember :
2077
- return bindPropertyOrMethodOrAccessor ( < Declaration > node , SymbolFlags . Property | ( ( < PropertyDeclaration > node ) . questionToken ? SymbolFlags . Optional : SymbolFlags . None ) , SymbolFlags . PropertyExcludes ) ;
2078
- case SyntaxKind . JSDocPropertyTag :
2079
- return bindJSDocProperty ( < JSDocPropertyTag > node ) ;
2073
+ return bindPropertyWorker ( node as PropertyDeclaration | PropertySignature ) ;
2080
2074
case SyntaxKind . PropertyAssignment :
2081
2075
case SyntaxKind . ShorthandPropertyAssignment :
2082
2076
return bindPropertyOrMethodOrAccessor ( < Declaration > node , SymbolFlags . Property , SymbolFlags . PropertyExcludes ) ;
@@ -2121,13 +2115,10 @@ namespace ts {
2121
2115
return bindPropertyOrMethodOrAccessor ( < Declaration > node , SymbolFlags . SetAccessor , SymbolFlags . SetAccessorExcludes ) ;
2122
2116
case SyntaxKind . FunctionType :
2123
2117
case SyntaxKind . ConstructorType :
2124
- case SyntaxKind . JSDocFunctionType :
2125
2118
return bindFunctionOrConstructorType ( < SignatureDeclaration > node ) ;
2126
2119
case SyntaxKind . TypeLiteral :
2127
2120
case SyntaxKind . MappedType :
2128
- case SyntaxKind . JSDocTypeLiteral :
2129
- case SyntaxKind . JSDocRecordType :
2130
- return bindAnonymousDeclaration ( < Declaration > node , SymbolFlags . TypeLiteral , "__type" ) ;
2121
+ return bindAnonymousTypeWorker ( node as TypeLiteralNode | MappedTypeNode ) ;
2131
2122
case SyntaxKind . ObjectLiteralExpression :
2132
2123
return bindObjectLiteralExpression ( < ObjectLiteralExpression > node ) ;
2133
2124
case SyntaxKind . FunctionExpression :
@@ -2148,11 +2139,6 @@ namespace ts {
2148
2139
return bindClassLikeDeclaration ( < ClassLikeDeclaration > node ) ;
2149
2140
case SyntaxKind . InterfaceDeclaration :
2150
2141
return bindBlockScopedDeclaration ( < Declaration > node , SymbolFlags . Interface , SymbolFlags . InterfaceExcludes ) ;
2151
- case SyntaxKind . JSDocTypedefTag :
2152
- if ( ! ( < JSDocTypedefTag > node ) . fullName || ( < JSDocTypedefTag > node ) . fullName . kind === SyntaxKind . Identifier ) {
2153
- return bindBlockScopedDeclaration ( < Declaration > node , SymbolFlags . TypeAlias , SymbolFlags . TypeAliasExcludes ) ;
2154
- }
2155
- break ;
2156
2142
case SyntaxKind . TypeAliasDeclaration :
2157
2143
return bindBlockScopedDeclaration ( < Declaration > node , SymbolFlags . TypeAlias , SymbolFlags . TypeAliasExcludes ) ;
2158
2144
case SyntaxKind . EnumDeclaration :
@@ -2190,9 +2176,41 @@ namespace ts {
2190
2176
// falls through
2191
2177
case SyntaxKind . ModuleBlock :
2192
2178
return updateStrictModeStatementList ( ( < Block | ModuleBlock > node ) . statements ) ;
2179
+
2180
+ default :
2181
+ if ( isInJavaScriptFile ( node ) ) return bindJSDocWorker ( node ) ;
2193
2182
}
2194
2183
}
2195
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
+ }
2203
+ }
2204
+ }
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
+
2196
2214
function checkTypePredicate ( node : TypePredicateNode ) {
2197
2215
const { parameterName, type } = node ;
2198
2216
if ( parameterName && parameterName . kind === SyntaxKind . Identifier ) {
@@ -2558,10 +2576,8 @@ namespace ts {
2558
2576
}
2559
2577
2560
2578
function bindPropertyOrMethodOrAccessor ( node : Declaration , symbolFlags : SymbolFlags , symbolExcludes : SymbolFlags ) {
2561
- if ( ! file . isDeclarationFile && ! isInAmbientContext ( node ) ) {
2562
- if ( isAsyncFunction ( node ) ) {
2563
- emitFlags |= NodeFlags . HasAsyncFunctions ;
2564
- }
2579
+ if ( ! file . isDeclarationFile && ! isInAmbientContext ( node ) && isAsyncFunction ( node ) ) {
2580
+ emitFlags |= NodeFlags . HasAsyncFunctions ;
2565
2581
}
2566
2582
2567
2583
if ( currentFlow && isObjectLiteralOrClassExpressionMethod ( node ) ) {
@@ -2573,10 +2589,6 @@ namespace ts {
2573
2589
: declareSymbolAndAddToSymbolTable ( node , symbolFlags , symbolExcludes ) ;
2574
2590
}
2575
2591
2576
- function bindJSDocProperty ( node : JSDocPropertyTag ) {
2577
- return declareSymbolAndAddToSymbolTable ( node , SymbolFlags . Property , SymbolFlags . PropertyExcludes ) ;
2578
- }
2579
-
2580
2592
// reachability checks
2581
2593
2582
2594
function shouldReportErrorOnModuleDeclaration ( node : ModuleDeclaration ) : boolean {
0 commit comments