@@ -595,7 +595,19 @@ namespace ts {
595
595
// Binding of JsDocComment should be done before the current block scope container changes.
596
596
// because the scope of JsDocComment should not be affected by whether the current node is a
597
597
// container or not.
598
- forEach ( node . jsDoc , bind ) ;
598
+ if ( node . jsDoc ) {
599
+ if ( isInJavaScriptFile ( node ) ) {
600
+ for ( const j of node . jsDoc ) {
601
+ bind ( j ) ;
602
+ }
603
+ }
604
+ else {
605
+ for ( const j of node . jsDoc ) {
606
+ setParentPointers ( node , j ) ;
607
+ }
608
+ }
609
+ }
610
+
599
611
if ( checkUnreachable ( node ) ) {
600
612
bindEachChild ( node ) ;
601
613
return ;
@@ -1903,7 +1915,7 @@ namespace ts {
1903
1915
// Here the current node is "foo", which is a container, but the scope of "MyType" should
1904
1916
// not be inside "foo". Therefore we always bind @typedef before bind the parent node,
1905
1917
// and skip binding this tag later when binding all the other jsdoc tags.
1906
- bindJSDocTypedefTagIfAny ( node ) ;
1918
+ if ( isInJavaScriptFile ( node ) ) bindJSDocTypedefTagIfAny ( node ) ;
1907
1919
1908
1920
// First we bind declaration nodes to a symbol if possible. We'll both create a symbol
1909
1921
// and then potentially add the symbol to an appropriate symbol table. Possible
@@ -1991,7 +2003,7 @@ namespace ts {
1991
2003
// for typedef type names with namespaces, bind the new jsdoc type symbol here
1992
2004
// because it requires all containing namespaces to be in effect, namely the
1993
2005
// current "blockScopeContainer" needs to be set to its immediate namespace parent.
1994
- if ( isInJavaScriptFile ( node ) && ( < Identifier > node ) . isInJSDocNamespace ) {
2006
+ if ( ( < Identifier > node ) . isInJSDocNamespace ) {
1995
2007
let parentNode = node . parent ;
1996
2008
while ( parentNode && parentNode . kind !== SyntaxKind . JSDocTypedefTag ) {
1997
2009
parentNode = parentNode . parent ;
@@ -2053,10 +2065,7 @@ namespace ts {
2053
2065
case SyntaxKind . TypePredicate :
2054
2066
return checkTypePredicate ( node as TypePredicateNode ) ;
2055
2067
case SyntaxKind . TypeParameter :
2056
- if ( node . parent . kind !== ts . SyntaxKind . JSDocTemplateTag || isInJavaScriptFile ( node ) ) {
2057
- return declareSymbolAndAddToSymbolTable ( < Declaration > node , SymbolFlags . TypeParameter , SymbolFlags . TypeParameterExcludes ) ;
2058
- }
2059
- return ;
2068
+ return declareSymbolAndAddToSymbolTable ( < Declaration > node , SymbolFlags . TypeParameter , SymbolFlags . TypeParameterExcludes ) ;
2060
2069
case SyntaxKind . Parameter :
2061
2070
return bindParameter ( < ParameterDeclaration > node ) ;
2062
2071
case SyntaxKind . VariableDeclaration :
@@ -2138,10 +2147,7 @@ namespace ts {
2138
2147
case SyntaxKind . EnumDeclaration :
2139
2148
return bindEnumDeclaration ( < EnumDeclaration > node ) ;
2140
2149
case SyntaxKind . ModuleDeclaration :
2141
- if ( node . parent . kind !== ts . SyntaxKind . JSDocTypedefTag || isInJavaScriptFile ( node ) ) {
2142
- return bindModuleDeclaration ( < ModuleDeclaration > node ) ;
2143
- }
2144
- return undefined ;
2150
+ return bindModuleDeclaration ( < ModuleDeclaration > node ) ;
2145
2151
// Jsx-attributes
2146
2152
case SyntaxKind . JsxAttributes :
2147
2153
return bindJsxAttributes ( < JsxAttributes > node ) ;
@@ -2173,13 +2179,6 @@ namespace ts {
2173
2179
case SyntaxKind . ModuleBlock :
2174
2180
return updateStrictModeStatementList ( ( < Block | ModuleBlock > node ) . statements ) ;
2175
2181
2176
- default :
2177
- if ( isInJavaScriptFile ( node ) ) return bindJSDocWorker ( node ) ;
2178
- }
2179
- }
2180
-
2181
- function bindJSDocWorker ( node : Node ) {
2182
- switch ( node . kind ) {
2183
2182
case SyntaxKind . JSDocRecordMember :
2184
2183
return bindPropertyWorker ( node as JSDocRecordMember ) ;
2185
2184
case SyntaxKind . JSDocPropertyTag :
@@ -3605,4 +3604,13 @@ namespace ts {
3605
3604
return TransformFlags . NodeExcludes ;
3606
3605
}
3607
3606
}
3607
+
3608
+ /**
3609
+ * "Binds" JSDoc nodes in TypeScript code.
3610
+ * Since we will never create symbols for JSDoc, we just set parent pointers instead.
3611
+ */
3612
+ function setParentPointers ( parent : Node , child : Node ) : void {
3613
+ child . parent = parent ;
3614
+ forEachChild ( child , ( childsChild ) => setParentPointers ( child , childsChild ) ) ;
3615
+ }
3608
3616
}
0 commit comments