@@ -21,12 +21,6 @@ class ExprOrType extends @exprortype, Documentable {
2121 /** Gets the function in which this expression or type appears, if any. */
2222 Function getEnclosingFunction ( ) { result = getContainer ( ) }
2323
24- /**
25- * Gets the statement container (function or toplevel) in which
26- * this expression or type appears.
27- */
28- StmtContainer getContainer ( ) { exprContainers ( this , result ) }
29-
3024 /**
3125 * Gets the JSDoc comment associated with this expression or type or its parent statement, if any.
3226 */
@@ -107,12 +101,6 @@ class ExprOrType extends @exprortype, Documentable {
107101 * ```
108102 */
109103class Expr extends @expr, ExprOrStmt , ExprOrType , AST:: ValueNode {
110- /**
111- * Gets the statement container (function or toplevel) in which
112- * this expression appears.
113- */
114- override StmtContainer getContainer ( ) { exprContainers ( this , result ) }
115-
116104 /** Gets this expression, with any surrounding parentheses removed. */
117105 override Expr stripParens ( ) { result = this }
118106
@@ -246,25 +234,32 @@ class Expr extends @expr, ExprOrStmt, ExprOrType, AST::ValueNode {
246234 )
247235 }
248236
237+ pragma [ inline]
238+ private Stmt getRawEnclosingStmt ( Expr e ) {
239+ // For performance reasons, we need the enclosing statement without overrides
240+ enclosingStmt ( e , result )
241+ }
242+
249243 /**
250244 * Gets the data-flow node where exceptions thrown by this expression will
251245 * propagate if this expression causes an exception to be thrown.
252246 */
247+ pragma [ inline]
253248 DataFlow:: Node getExceptionTarget ( ) {
254- if exists ( this .getEnclosingStmt ( ) .getEnclosingTryCatchStmt ( ) )
255- then
256- result =
257- DataFlow:: parameterNode ( this
258- .getEnclosingStmt ( )
259- .getEnclosingTryCatchStmt ( )
260- .getACatchClause ( )
261- .getAParameter ( ) )
262- else
263- result =
264- any ( DataFlow:: FunctionNode f | f .getFunction ( ) = this .getContainer ( ) ) .getExceptionalReturn ( )
249+ result = getCatchParameterFromStmt ( getRawEnclosingStmt ( this ) )
250+ or
251+ not exists ( getCatchParameterFromStmt ( getRawEnclosingStmt ( this ) ) ) and
252+ result =
253+ any ( DataFlow:: FunctionNode f | f .getFunction ( ) = this .getContainer ( ) ) .getExceptionalReturn ( )
265254 }
266255}
267256
257+ cached
258+ private DataFlow:: Node getCatchParameterFromStmt ( Stmt stmt ) {
259+ result =
260+ DataFlow:: parameterNode ( stmt .getEnclosingTryCatchStmt ( ) .getACatchClause ( ) .getAParameter ( ) )
261+ }
262+
268263/**
269264 * An identifier.
270265 *
@@ -633,9 +628,6 @@ class Property extends @property, Documentable {
633628 /** Gets the (0-based) index at which this property appears in its enclosing literal. */
634629 int getIndex ( ) { this = getObjectExpr ( ) .getProperty ( result ) }
635630
636- /** Gets the function or toplevel in which this property occurs. */
637- StmtContainer getContainer ( ) { result = getObjectExpr ( ) .getContainer ( ) }
638-
639631 /**
640632 * Holds if this property is impure, that is, the evaluation of its name or
641633 * its initializer expression could have side effects.
0 commit comments