@@ -198,16 +198,36 @@ class NewNode extends InvokeNode {
198198 override DataFlow:: Impl:: NewNodeDef impl ;
199199}
200200
201- /** A data flow node corresponding to a `this` expression. */
202- class ThisNode extends DataFlow:: ValueNode , DataFlow:: DefaultSourceNode {
203- override ThisExpr astNode ;
201+ /** A data flow node corresponding to the `this` parameter in a function or `this` at the top-level. */
202+ class ThisNode extends DataFlow:: Node , DataFlow:: DefaultSourceNode {
203+ ThisNode ( ) {
204+ DataFlow:: thisNode ( this , _)
205+ }
204206
205207 /**
206208 * Gets the function whose `this` binding this expression refers to,
207209 * which is the nearest enclosing non-arrow function.
208210 */
209211 FunctionNode getBinder ( ) {
210- result = DataFlow:: valueNode ( astNode .getBinder ( ) )
212+ exists ( Function binder |
213+ DataFlow:: thisNode ( this , binder ) and
214+ result = DataFlow:: valueNode ( binder ) )
215+ }
216+
217+ /**
218+ * Gets the function or top-level whose `this` binding this expression refers to,
219+ * which is the nearest enclosing non-arrow function or top-level.
220+ */
221+ StmtContainer getBindingContainer ( ) {
222+ DataFlow:: thisNode ( this , result )
223+ }
224+
225+ override string toString ( ) { result = "this" }
226+
227+ override predicate hasLocationInfo ( string filepath , int startline , int startcolumn ,
228+ int endline , int endcolumn ) {
229+ // Use the function entry as the location
230+ getBindingContainer ( ) .getEntry ( ) .getLocation ( ) .hasLocationInfo ( filepath , startline , startcolumn , endline , endcolumn )
211231 }
212232}
213233
0 commit comments