@@ -260,18 +260,9 @@ namespace ts {
260
260
case SyntaxKind . ExportAssignment :
261
261
return ( < ExportAssignment > node ) . isExportEquals ? "export=" : "default" ;
262
262
case SyntaxKind . BinaryExpression :
263
- switch ( getSpecialPropertyAssignmentKind ( node as BinaryExpression ) ) {
264
- case SpecialPropertyAssignmentKind . ModuleExports :
265
- // module.exports = ...
266
- return "export=" ;
267
- case SpecialPropertyAssignmentKind . ExportsProperty :
268
- case SpecialPropertyAssignmentKind . ThisProperty :
269
- case SpecialPropertyAssignmentKind . Property :
270
- // exports.x = ... or this.y = ...
271
- return ( ( node as BinaryExpression ) . left as PropertyAccessExpression ) . name . text ;
272
- case SpecialPropertyAssignmentKind . PrototypeProperty :
273
- // className.prototype.methodName = ...
274
- return ( ( ( node as BinaryExpression ) . left as PropertyAccessExpression ) . expression as PropertyAccessExpression ) . name . text ;
263
+ if ( getSpecialPropertyAssignmentKind ( node as BinaryExpression ) === SpecialPropertyAssignmentKind . ModuleExports ) {
264
+ // module.exports = ...
265
+ return "export=" ;
275
266
}
276
267
Debug . fail ( "Unknown binary declaration kind" ) ;
277
268
break ;
@@ -439,6 +430,7 @@ namespace ts {
439
430
// during global merging in the checker. Why? The only case when ambient module is permitted inside another module is module augmentation
440
431
// and this case is specially handled. Module augmentations should only be merged with original module definition
441
432
// and should never be merged directly with other augmentation, and the latter case would be possible if automatic merge is allowed.
433
+ if ( node . kind === SyntaxKind . JSDocTypedefTag ) Debug . assert ( isInJavaScriptFile ( node ) ) ; // We shouldn't add symbols for JSDoc nodes if not in a JS file.
442
434
const isJSDocTypedefInJSDocNamespace = node . kind === SyntaxKind . JSDocTypedefTag &&
443
435
( node as JSDocTypedefTag ) . name &&
444
436
( node as JSDocTypedefTag ) . name . kind === SyntaxKind . Identifier &&
@@ -603,9 +595,7 @@ namespace ts {
603
595
// Binding of JsDocComment should be done before the current block scope container changes.
604
596
// because the scope of JsDocComment should not be affected by whether the current node is a
605
597
// container or not.
606
- if ( isInJavaScriptFile ( node ) && node . jsDoc ) {
607
- forEach ( node . jsDoc , bind ) ;
608
- }
598
+ forEach ( node . jsDoc , bind ) ;
609
599
if ( checkUnreachable ( node ) ) {
610
600
bindEachChild ( node ) ;
611
601
return ;
@@ -1913,9 +1903,7 @@ namespace ts {
1913
1903
// Here the current node is "foo", which is a container, but the scope of "MyType" should
1914
1904
// not be inside "foo". Therefore we always bind @typedef before bind the parent node,
1915
1905
// and skip binding this tag later when binding all the other jsdoc tags.
1916
- if ( isInJavaScriptFile ( node ) ) {
1917
- bindJSDocTypedefTagIfAny ( node ) ;
1918
- }
1906
+ bindJSDocTypedefTagIfAny ( node ) ;
1919
1907
1920
1908
// First we bind declaration nodes to a symbol if possible. We'll both create a symbol
1921
1909
// and then potentially add the symbol to an appropriate symbol table. Possible
@@ -2003,7 +1991,7 @@ namespace ts {
2003
1991
// for typedef type names with namespaces, bind the new jsdoc type symbol here
2004
1992
// because it requires all containing namespaces to be in effect, namely the
2005
1993
// current "blockScopeContainer" needs to be set to its immediate namespace parent.
2006
- if ( ( < Identifier > node ) . isInJSDocNamespace ) {
1994
+ if ( isInJavaScriptFile ( node ) && ( < Identifier > node ) . isInJSDocNamespace ) {
2007
1995
let parentNode = node . parent ;
2008
1996
while ( parentNode && parentNode . kind !== SyntaxKind . JSDocTypedefTag ) {
2009
1997
parentNode = parentNode . parent ;
@@ -2073,10 +2061,7 @@ namespace ts {
2073
2061
return bindVariableDeclarationOrBindingElement ( < VariableDeclaration | BindingElement > node ) ;
2074
2062
case SyntaxKind . PropertyDeclaration :
2075
2063
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 ) ;
2064
+ return bindPropertyWorker ( node as PropertyDeclaration | PropertySignature ) ;
2080
2065
case SyntaxKind . PropertyAssignment :
2081
2066
case SyntaxKind . ShorthandPropertyAssignment :
2082
2067
return bindPropertyOrMethodOrAccessor ( < Declaration > node , SymbolFlags . Property , SymbolFlags . PropertyExcludes ) ;
@@ -2121,13 +2106,10 @@ namespace ts {
2121
2106
return bindPropertyOrMethodOrAccessor ( < Declaration > node , SymbolFlags . SetAccessor , SymbolFlags . SetAccessorExcludes ) ;
2122
2107
case SyntaxKind . FunctionType :
2123
2108
case SyntaxKind . ConstructorType :
2124
- case SyntaxKind . JSDocFunctionType :
2125
2109
return bindFunctionOrConstructorType ( < SignatureDeclaration > node ) ;
2126
2110
case SyntaxKind . TypeLiteral :
2127
2111
case SyntaxKind . MappedType :
2128
- case SyntaxKind . JSDocTypeLiteral :
2129
- case SyntaxKind . JSDocRecordType :
2130
- return bindAnonymousDeclaration ( < Declaration > node , SymbolFlags . TypeLiteral , "__type" ) ;
2112
+ return bindAnonymousTypeWorker ( node as TypeLiteralNode | MappedTypeNode ) ;
2131
2113
case SyntaxKind . ObjectLiteralExpression :
2132
2114
return bindObjectLiteralExpression ( < ObjectLiteralExpression > node ) ;
2133
2115
case SyntaxKind . FunctionExpression :
@@ -2148,11 +2130,6 @@ namespace ts {
2148
2130
return bindClassLikeDeclaration ( < ClassLikeDeclaration > node ) ;
2149
2131
case SyntaxKind . InterfaceDeclaration :
2150
2132
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
2133
case SyntaxKind . TypeAliasDeclaration :
2157
2134
return bindBlockScopedDeclaration ( < Declaration > node , SymbolFlags . TypeAlias , SymbolFlags . TypeAliasExcludes ) ;
2158
2135
case SyntaxKind . EnumDeclaration :
@@ -2190,9 +2167,41 @@ namespace ts {
2190
2167
// falls through
2191
2168
case SyntaxKind . ModuleBlock :
2192
2169
return updateStrictModeStatementList ( ( < Block | ModuleBlock > node ) . statements ) ;
2170
+
2171
+ default :
2172
+ if ( isInJavaScriptFile ( node ) ) return bindJSDocWorker ( node ) ;
2173
+ }
2174
+ }
2175
+
2176
+ function bindJSDocWorker ( node : Node ) {
2177
+ switch ( node . kind ) {
2178
+ case SyntaxKind . JSDocRecordMember :
2179
+ return bindPropertyWorker ( node as JSDocRecordMember ) ;
2180
+ case SyntaxKind . JSDocPropertyTag :
2181
+ return declareSymbolAndAddToSymbolTable ( node as JSDocPropertyTag , SymbolFlags . Property , SymbolFlags . PropertyExcludes ) ;
2182
+ case SyntaxKind . JSDocFunctionType :
2183
+ return bindFunctionOrConstructorType ( < SignatureDeclaration > node ) ;
2184
+ case SyntaxKind . JSDocTypeLiteral :
2185
+ case SyntaxKind . JSDocRecordType :
2186
+ return bindAnonymousTypeWorker ( node as JSDocTypeLiteral | JSDocRecordType ) ;
2187
+ case SyntaxKind . JSDocTypedefTag : {
2188
+ const { fullName } = node as JSDocTypedefTag ;
2189
+ if ( ! fullName || fullName . kind === SyntaxKind . Identifier ) {
2190
+ return bindBlockScopedDeclaration ( < Declaration > node , SymbolFlags . TypeAlias , SymbolFlags . TypeAliasExcludes ) ;
2191
+ }
2192
+ break ;
2193
+ }
2193
2194
}
2194
2195
}
2195
2196
2197
+ function bindPropertyWorker ( node : PropertyDeclaration | PropertySignature ) {
2198
+ return bindPropertyOrMethodOrAccessor ( node , SymbolFlags . Property | ( node . questionToken ? SymbolFlags . Optional : SymbolFlags . None ) , SymbolFlags . PropertyExcludes ) ;
2199
+ }
2200
+
2201
+ function bindAnonymousTypeWorker ( node : TypeLiteralNode | MappedTypeNode | JSDocTypeLiteral | JSDocRecordType ) {
2202
+ return bindAnonymousDeclaration ( < Declaration > node , SymbolFlags . TypeLiteral , "__type" ) ;
2203
+ }
2204
+
2196
2205
function checkTypePredicate ( node : TypePredicateNode ) {
2197
2206
const { parameterName, type } = node ;
2198
2207
if ( parameterName && parameterName . kind === SyntaxKind . Identifier ) {
@@ -2558,10 +2567,8 @@ namespace ts {
2558
2567
}
2559
2568
2560
2569
function bindPropertyOrMethodOrAccessor ( node : Declaration , symbolFlags : SymbolFlags , symbolExcludes : SymbolFlags ) {
2561
- if ( ! file . isDeclarationFile && ! isInAmbientContext ( node ) ) {
2562
- if ( isAsyncFunction ( node ) ) {
2563
- emitFlags |= NodeFlags . HasAsyncFunctions ;
2564
- }
2570
+ if ( ! file . isDeclarationFile && ! isInAmbientContext ( node ) && isAsyncFunction ( node ) ) {
2571
+ emitFlags |= NodeFlags . HasAsyncFunctions ;
2565
2572
}
2566
2573
2567
2574
if ( currentFlow && isObjectLiteralOrClassExpressionMethod ( node ) ) {
@@ -2573,10 +2580,6 @@ namespace ts {
2573
2580
: declareSymbolAndAddToSymbolTable ( node , symbolFlags , symbolExcludes ) ;
2574
2581
}
2575
2582
2576
- function bindJSDocProperty ( node : JSDocPropertyTag ) {
2577
- return declareSymbolAndAddToSymbolTable ( node , SymbolFlags . Property , SymbolFlags . PropertyExcludes ) ;
2578
- }
2579
-
2580
2583
// reachability checks
2581
2584
2582
2585
function shouldReportErrorOnModuleDeclaration ( node : ModuleDeclaration ) : boolean {
0 commit comments