44
55import javascript
66private import internal.StmtContainers
7+ private import semmle.javascript.internal.CachedStages
78
89/**
910 * A program element corresponding to JavaScript code, such as an expression
@@ -75,7 +76,7 @@ class ASTNode extends @ast_node, NodeInStmtContainer {
7576
7677 /** Gets the toplevel syntactic unit to which this element belongs. */
7778 cached
78- TopLevel getTopLevel ( ) { result = getParent ( ) .getTopLevel ( ) }
79+ TopLevel getTopLevel ( ) { Stages :: Ast :: ref ( ) and result = getParent ( ) .getTopLevel ( ) }
7980
8081 /**
8182 * Gets the `i`th child node of this node.
@@ -119,7 +120,7 @@ class ASTNode extends @ast_node, NodeInStmtContainer {
119120
120121 /** Gets the parent node of this node, if any. */
121122 cached
122- ASTNode getParent ( ) { this = result .getAChild ( ) }
123+ ASTNode getParent ( ) { Stages :: Ast :: ref ( ) and this = result .getAChild ( ) }
123124
124125 /** Gets the first control flow node belonging to this syntactic entity. */
125126 ControlFlowNode getFirstControlFlowNode ( ) { result = this }
@@ -135,6 +136,7 @@ class ASTNode extends @ast_node, NodeInStmtContainer {
135136 */
136137 cached
137138 private predicate isAmbientInternal ( ) {
139+ Stages:: Ast:: ref ( ) and
138140 getParent ( ) .isAmbientInternal ( )
139141 or
140142 not isAmbientTopLevel ( getTopLevel ( ) ) and
@@ -186,7 +188,9 @@ class ASTNode extends @ast_node, NodeInStmtContainer {
186188 * Holds if the given file is a `.d.ts` file.
187189 */
188190cached
189- private predicate isAmbientTopLevel ( TopLevel tl ) { tl .getFile ( ) .getBaseName ( ) .matches ( "%.d.ts" ) }
191+ private predicate isAmbientTopLevel ( TopLevel tl ) {
192+ Stages:: Ast:: ref ( ) and tl .getFile ( ) .getBaseName ( ) .matches ( "%.d.ts" )
193+ }
190194
191195/**
192196 * A toplevel syntactic unit; that is, a stand-alone script, an inline script
0 commit comments