@@ -17,7 +17,8 @@ namespace ts {
1717 export function getModuleInstanceState ( node : ModuleDeclaration , visited ?: Map < ModuleInstanceState | undefined > ) : ModuleInstanceState {
1818 if ( node . body && ! node . body . parent ) {
1919 // getModuleInstanceStateForAliasTarget needs to walk up the parent chain, so parent pointers must be set on this tree already
20- setParentPointers ( node , node . body ) ;
20+ setParent ( node . body , node ) ;
21+ setParentRecursive ( node . body , /*incremental*/ false ) ;
2122 }
2223 return node . body ? getModuleInstanceStateCached ( node . body , visited ) : ModuleInstanceState . Instantiated ;
2324 }
@@ -114,7 +115,8 @@ namespace ts {
114115 for ( const statement of statements ) {
115116 if ( nodeHasName ( statement , name ) ) {
116117 if ( ! statement . parent ) {
117- setParentPointers ( p , statement ) ;
118+ setParent ( statement , p ) ;
119+ setParentRecursive ( statement , /*incremental*/ false ) ;
118120 }
119121 const state = getModuleInstanceStateCached ( statement , visited ) ;
120122 if ( found === undefined || state > found ) {
@@ -467,7 +469,7 @@ namespace ts {
467469 else if ( ! ( includes & SymbolFlags . Variable && symbol . flags & SymbolFlags . Assignment ) ) {
468470 // Assignment declarations are allowed to merge with variables, no matter what other flags they have.
469471 if ( isNamedDeclaration ( node ) ) {
470- node . name . parent = node ;
472+ setParent ( node . name , node ) ;
471473 }
472474
473475 // Report errors every position with duplicate declaration
@@ -1484,9 +1486,10 @@ namespace ts {
14841486 }
14851487
14861488 function bindJSDocTypeAlias ( node : JSDocTypedefTag | JSDocCallbackTag | JSDocEnumTag ) {
1487- node . tagName . parent = node ;
1489+ setParent ( node . tagName , node ) ;
14881490 if ( node . kind !== SyntaxKind . JSDocEnumTag && node . fullName ) {
1489- setParentPointers ( node , node . fullName ) ;
1491+ setParent ( node . fullName , node ) ;
1492+ setParentRecursive ( node . fullName , /*incremental*/ false ) ;
14901493 }
14911494 }
14921495
@@ -2174,7 +2177,7 @@ namespace ts {
21742177 if ( ! node ) {
21752178 return ;
21762179 }
2177- node . parent = parent ;
2180+ setParent ( node , parent ) ;
21782181 const saveInStrictMode = inStrictMode ;
21792182
21802183 // Even though in the AST the jsdoc @typedef node belongs to the current node,
@@ -2233,7 +2236,8 @@ namespace ts {
22332236 }
22342237 else {
22352238 for ( const j of node . jsDoc ! ) {
2236- setParentPointers ( node , j ) ;
2239+ setParent ( j , node ) ;
2240+ setParentRecursive ( j , /*incremental*/ false ) ;
22372241 }
22382242 }
22392243 }
@@ -2726,8 +2730,8 @@ namespace ts {
27262730
27272731 /** For `x.prototype = { p, ... }`, declare members p,... if `x` is function/class/{}, or not declared. */
27282732 function bindPrototypeAssignment ( node : BindableStaticPropertyAssignmentExpression ) {
2729- node . left . parent = node ;
2730- node . right . parent = node ;
2733+ setParent ( node . left , node ) ;
2734+ setParent ( node . right , node ) ;
27312735 bindPropertyAssignment ( node . left . expression , node . left , /*isPrototypeProperty*/ false , /*containerIsClass*/ true ) ;
27322736 }
27332737
@@ -2751,9 +2755,9 @@ namespace ts {
27512755 const constructorFunction = classPrototype . expression ;
27522756
27532757 // Fix up parent pointers since we're going to use these nodes before we bind into them
2754- lhs . parent = parent ;
2755- constructorFunction . parent = classPrototype ;
2756- classPrototype . parent = lhs ;
2758+ setParent ( constructorFunction , classPrototype ) ;
2759+ setParent ( classPrototype , lhs ) ;
2760+ setParent ( lhs , parent ) ;
27572761
27582762 bindPropertyAssignment ( constructorFunction , lhs , /*isPrototypeProperty*/ true , /*containerIsClass*/ true ) ;
27592763 }
@@ -2772,8 +2776,8 @@ namespace ts {
27722776 return ;
27732777 }
27742778 // Fix up parent pointers since we're going to use these nodes before we bind into them
2775- node . left . parent = node ;
2776- node . right . parent = node ;
2779+ setParent ( node . left , node ) ;
2780+ setParent ( node . right , node ) ;
27772781 if ( isIdentifier ( node . left . expression ) && container === file && isExportsOrModuleExportsOrAlias ( file , node . left . expression ) ) {
27782782 // This can be an alias for the 'exports' or 'module.exports' names, e.g.
27792783 // var util = module.exports;
@@ -2797,7 +2801,7 @@ namespace ts {
27972801 * Also works for expression statements preceded by JSDoc, like / ** @type number * / x.y;
27982802 */
27992803 function bindStaticPropertyAssignment ( node : BindableStaticAccessExpression ) {
2800- node . expression . parent = node ;
2804+ setParent ( node . expression , node ) ;
28012805 bindPropertyAssignment ( node . expression , node , /*isPrototypeProperty*/ false , /*containerIsClass*/ false ) ;
28022806 }
28032807
@@ -2979,7 +2983,7 @@ namespace ts {
29792983 const symbolExport = symbol . exports ! . get ( prototypeSymbol . escapedName ) ;
29802984 if ( symbolExport ) {
29812985 if ( node . name ) {
2982- node . name . parent = node ;
2986+ setParent ( node . name , node ) ;
29832987 }
29842988 file . bindDiagnostics . push ( createDiagnosticForNode ( symbolExport . declarations [ 0 ] , Diagnostics . Duplicate_identifier_0 , symbolName ( prototypeSymbol ) ) ) ;
29852989 }
@@ -3241,13 +3245,4 @@ namespace ts {
32413245 }
32423246 return container . symbol && container . symbol . exports && container . symbol . exports . get ( name ) ;
32433247 }
3244-
3245- /**
3246- * "Binds" JSDoc nodes in TypeScript code.
3247- * Since we will never create symbols for JSDoc, we just set parent pointers instead.
3248- */
3249- function setParentPointers ( parent : Node , child : Node ) : void {
3250- child . parent = parent ;
3251- forEachChild ( child , grandchild => setParentPointers ( child , grandchild ) ) ;
3252- }
32533248}
0 commit comments