@@ -263,6 +263,18 @@ namespace ts {
263
263
let functionType = < JSDocFunctionType > node . parent ;
264
264
let index = indexOf ( functionType . parameters , node ) ;
265
265
return "p" + index ;
266
+ case SyntaxKind . JSDocTypedefTag :
267
+ const parentNode = node . parent && node . parent . parent ;
268
+ let nameFromParentNode : string ;
269
+ if ( parentNode && parentNode . kind === SyntaxKind . VariableStatement ) {
270
+ if ( ( < VariableStatement > parentNode ) . declarationList . declarations . length > 0 ) {
271
+ const nameIdentifier = ( < VariableStatement > parentNode ) . declarationList . declarations [ 0 ] . name ;
272
+ if ( nameIdentifier . kind === SyntaxKind . Identifier ) {
273
+ nameFromParentNode = ( < Identifier > nameIdentifier ) . text ;
274
+ }
275
+ }
276
+ }
277
+ return nameFromParentNode ;
266
278
}
267
279
}
268
280
@@ -402,6 +414,7 @@ namespace ts {
402
414
// these saved values.
403
415
const saveContainer = container ;
404
416
const savedBlockScopeContainer = blockScopeContainer ;
417
+
405
418
// Depending on what kind of node this is, we may have to adjust the current container
406
419
// and block-container. If the current node is a container, then it is automatically
407
420
// considered the current block-container as well. Also, for containers that we know
@@ -491,8 +504,13 @@ namespace ts {
491
504
}
492
505
493
506
function bindChildren ( node : Node ) : void {
494
- if ( node . flags & NodeFlags . JavaScriptFile && node . jsDocComment ) {
495
- bind ( node . jsDocComment ) ;
507
+ // Binding of JsDocComment should be done before the current block scope container changes.
508
+ // because the scope of JsDocComment should not be affected by whether the current node is a
509
+ // container or not.
510
+ if ( isInJavaScriptFile ( node ) && node . jsDocComments ) {
511
+ for ( const jsDocComment of node . jsDocComments ) {
512
+ bind ( jsDocComment ) ;
513
+ }
496
514
}
497
515
if ( checkUnreachable ( node ) ) {
498
516
forEachChild ( node , bind ) ;
@@ -1090,6 +1108,7 @@ namespace ts {
1090
1108
case SyntaxKind . EnumDeclaration :
1091
1109
case SyntaxKind . ObjectLiteralExpression :
1092
1110
case SyntaxKind . TypeLiteral :
1111
+ case SyntaxKind . JSDocTypeLiteral :
1093
1112
case SyntaxKind . JSDocRecordType :
1094
1113
return ContainerFlags . IsContainer ;
1095
1114
@@ -1190,6 +1209,7 @@ namespace ts {
1190
1209
case SyntaxKind . ObjectLiteralExpression :
1191
1210
case SyntaxKind . InterfaceDeclaration :
1192
1211
case SyntaxKind . JSDocRecordType :
1212
+ case SyntaxKind . JSDocTypeLiteral :
1193
1213
// Interface/Object-types always have their children added to the 'members' of
1194
1214
// their container. They are only accessible through an instance of their
1195
1215
// container, and are never in scope otherwise (even inside the body of the
@@ -1218,7 +1238,7 @@ namespace ts {
1218
1238
// their container in the tree. To accomplish this, we simply add their declared
1219
1239
// symbol to the 'locals' of the container. These symbols can then be found as
1220
1240
// the type checker walks up the containers, checking them for matching names.
1221
- return declareSymbol ( container . locals , undefined , node , symbolFlags , symbolExcludes ) ;
1241
+ return declareSymbol ( container . locals , /*parent*/ undefined , node , symbolFlags , symbolExcludes ) ;
1222
1242
}
1223
1243
}
1224
1244
@@ -1679,6 +1699,8 @@ namespace ts {
1679
1699
case SyntaxKind . PropertySignature :
1680
1700
case SyntaxKind . JSDocRecordMember :
1681
1701
return bindPropertyOrMethodOrAccessor ( < Declaration > node , SymbolFlags . Property | ( ( < PropertyDeclaration > node ) . questionToken ? SymbolFlags . Optional : SymbolFlags . None ) , SymbolFlags . PropertyExcludes ) ;
1702
+ case SyntaxKind . JSDocPropertyTag :
1703
+ return bindJSDocProperty ( < JSDocPropertyTag > node ) ;
1682
1704
case SyntaxKind . PropertyAssignment :
1683
1705
case SyntaxKind . ShorthandPropertyAssignment :
1684
1706
return bindPropertyOrMethodOrAccessor ( < Declaration > node , SymbolFlags . Property , SymbolFlags . PropertyExcludes ) ;
@@ -1714,6 +1736,7 @@ namespace ts {
1714
1736
case SyntaxKind . JSDocFunctionType :
1715
1737
return bindFunctionOrConstructorType ( < SignatureDeclaration > node ) ;
1716
1738
case SyntaxKind . TypeLiteral :
1739
+ case SyntaxKind . JSDocTypeLiteral :
1717
1740
case SyntaxKind . JSDocRecordType :
1718
1741
return bindAnonymousDeclaration ( < TypeLiteralNode > node , SymbolFlags . TypeLiteral , "__type" ) ;
1719
1742
case SyntaxKind . ObjectLiteralExpression :
@@ -1736,6 +1759,7 @@ namespace ts {
1736
1759
return bindClassLikeDeclaration ( < ClassLikeDeclaration > node ) ;
1737
1760
case SyntaxKind . InterfaceDeclaration :
1738
1761
return bindBlockScopedDeclaration ( < Declaration > node , SymbolFlags . Interface , SymbolFlags . InterfaceExcludes ) ;
1762
+ case SyntaxKind . JSDocTypedefTag :
1739
1763
case SyntaxKind . TypeAliasDeclaration :
1740
1764
return bindBlockScopedDeclaration ( < Declaration > node , SymbolFlags . TypeAlias , SymbolFlags . TypeAliasExcludes ) ;
1741
1765
case SyntaxKind . EnumDeclaration :
@@ -2077,6 +2101,10 @@ namespace ts {
2077
2101
: declareSymbolAndAddToSymbolTable ( node , symbolFlags , symbolExcludes ) ;
2078
2102
}
2079
2103
2104
+ function bindJSDocProperty ( node : JSDocPropertyTag ) {
2105
+ return declareSymbolAndAddToSymbolTable ( node , SymbolFlags . Property , SymbolFlags . PropertyExcludes ) ;
2106
+ }
2107
+
2080
2108
// reachability checks
2081
2109
2082
2110
function shouldReportErrorOnModuleDeclaration ( node : ModuleDeclaration ) : boolean {
0 commit comments