Skip to content

Commit 46c21f0

Browse files
committed
JS: Remove hasLocationInfo()
Removing this from DataFlow::Node is a breaking change, but we can't prevent its evaluation any other way.
1 parent a3235f5 commit 46c21f0

File tree

10 files changed

+32
-71
lines changed

10 files changed

+32
-71
lines changed

javascript/ql/lib/semmle/javascript/Routing.qll

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,17 @@ module Routing {
8383
/** Gets a textual representation of this element. */
8484
string toString() { none() } // Overridden in subclass
8585

86+
/** Gets the location of this node. */
87+
Location getLocation() { none() } // Overriden in subclass
88+
8689
/**
8790
* Holds if this element is at the specified location.
8891
* The location spans column `startcolumn` of line `startline` to
8992
* column `endcolumn` of line `endline` in file `filepath`.
9093
* For more information, see
9194
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries).
9295
*/
93-
predicate hasLocationInfo(
96+
deprecated predicate hasLocationInfo(
9497
string filepath, int startline, int startcolumn, int endline, int endcolumn
9598
) {
9699
none()
@@ -418,11 +421,7 @@ module Routing {
418421

419422
override string toString() { result = range.toString() }
420423

421-
override predicate hasLocationInfo(
422-
string filepath, int startline, int startcolumn, int endline, int endcolumn
423-
) {
424-
range.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
425-
}
424+
override Location getLocation() { result = range.getLocation() }
426425

427426
override Node getAChild() { result = range.getChild(_) }
428427

@@ -659,11 +658,7 @@ module Routing {
659658

660659
override string toString() { result = range.toString() }
661660

662-
override predicate hasLocationInfo(
663-
string filepath, int startline, int startcolumn, int endline, int endcolumn
664-
) {
665-
range.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
666-
}
661+
override Location getLocation() { result = range.getLocation() }
667662

668663
override Node getAChild() { result = range.getChild(_) }
669664

@@ -721,11 +716,7 @@ module Routing {
721716
[container.(Function).describe(), container.(TopLevel).getFile().getRelativePath()]
722717
}
723718

724-
override predicate hasLocationInfo(
725-
string filepath, int startline, int startcolumn, int endline, int endcolumn
726-
) {
727-
router.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
728-
}
719+
override Location getLocation() { result = router.getLocation() }
729720

730721
private RouteSetup::Base getARouteSetup() {
731722
result.isInstalledAt(router, any(ControlFlowNode cfg | cfg.getContainer() = container))

javascript/ql/lib/semmle/javascript/dataflow/Configuration.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1708,7 +1708,7 @@ deprecated class PathNode extends TPathNode {
17081708
predicate hasLocationInfo(
17091709
string filepath, int startline, int startcolumn, int endline, int endcolumn
17101710
) {
1711-
nd.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
1711+
nd.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
17121712
}
17131713

17141714
/**

javascript/ql/lib/semmle/javascript/dataflow/DataFlow.qll

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -150,19 +150,6 @@ module DataFlow {
150150
CallGraph::getABoundFunctionReference(result, boundArgs, _).flowsTo(this)
151151
}
152152

153-
/**
154-
* Holds if this element is at the specified location.
155-
* The location spans column `startcolumn` of line `startline` to
156-
* column `endcolumn` of line `endline` in file `filepath`.
157-
* For more information, see
158-
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
159-
*/
160-
final predicate hasLocationInfo(
161-
string filepath, int startline, int startcolumn, int endline, int endcolumn
162-
) {
163-
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
164-
}
165-
166153
/** Gets the location of this node. */
167154
cached
168155
Location getLocation() { none() }
@@ -171,16 +158,16 @@ module DataFlow {
171158
File getFile() { none() } // overridden in subclasses
172159

173160
/** Gets the start line of this data flow node. */
174-
int getStartLine() { this.hasLocationInfo(_, result, _, _, _) }
161+
int getStartLine() { result = this.getLocation().getStartLine() }
175162

176163
/** Gets the start column of this data flow node. */
177-
int getStartColumn() { this.hasLocationInfo(_, _, result, _, _) }
164+
int getStartColumn() { result = this.getLocation().getStartColumn() }
178165

179166
/** Gets the end line of this data flow node. */
180-
int getEndLine() { this.hasLocationInfo(_, _, _, result, _) }
167+
int getEndLine() { result = this.getLocation().getEndLine() }
181168

182169
/** Gets the end column of this data flow node. */
183-
int getEndColumn() { this.hasLocationInfo(_, _, _, _, result) }
170+
int getEndColumn() { result = this.getLocation().getEndColumn() }
184171

185172
/** Gets a textual representation of this element. */
186173
cached

javascript/ql/lib/semmle/javascript/dataflow/internal/DataFlowNode.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ private module Cached {
121121
DataFlowImplCommon::forceCachingInSameStage() or
122122
exists(any(DataFlow::Node node).toString()) or
123123
exists(any(DataFlow::Node node).getContainer()) or
124-
any(DataFlow::Node node).hasLocationInfo(_, _, _, _, _) or
124+
exists(any(DataFlow::Node node).getLocation()) or
125125
exists(any(Content c).toString())
126126
}
127127
}

javascript/ql/lib/semmle/javascript/frameworks/Vue.qll

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,17 @@ module Vue {
138138
/** Gets a textual representation of this element. */
139139
string toString() { none() } // overridden in subclasses
140140

141+
/** Gets the location of this component. */
142+
Location getLocation() { none() } // overridden in subclasses
143+
141144
/**
142145
* Holds if this element is at the specified location.
143146
* The location spans column `startcolumn` of line `startline` to
144147
* column `endcolumn` of line `endline` in file `filepath`.
145148
* For more information, see
146149
* [locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
147150
*/
148-
predicate hasLocationInfo(
151+
deprecated predicate hasLocationInfo(
149152
string filepath, int startline, int startcolumn, int endline, int endcolumn
150153
) {
151154
filepath = "" and
@@ -350,11 +353,7 @@ module Vue {
350353

351354
override string toString() { result = def.toString() }
352355

353-
override predicate hasLocationInfo(
354-
string filepath, int startline, int startcolumn, int endline, int endcolumn
355-
) {
356-
def.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
357-
}
356+
override Location getLocation() { result = def.getLocation() }
358357

359358
override API::Node getComponentRef() {
360359
// The Vue.extend call is made in the Vue framework; there is no explicit reference
@@ -383,11 +382,7 @@ module Vue {
383382

384383
override string toString() { result = extend.toString() }
385384

386-
override predicate hasLocationInfo(
387-
string filepath, int startline, int startcolumn, int endline, int endcolumn
388-
) {
389-
extend.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
390-
}
385+
override Location getLocation() { result = extend.getLocation() }
391386

392387
override API::Node getComponentRef() { result = extend.getReturn() }
393388

@@ -412,11 +407,7 @@ module Vue {
412407

413408
override string toString() { result = def.toString() }
414409

415-
override predicate hasLocationInfo(
416-
string filepath, int startline, int startcolumn, int endline, int endcolumn
417-
) {
418-
def.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
419-
}
410+
override Location getLocation() { result = def.getLocation() }
420411

421412
override API::Node getComponentRef() {
422413
// The component can be obtained via 1-argument calls to `Vue.component()` with the
@@ -477,15 +468,7 @@ module Vue {
477468
)
478469
}
479470

480-
override predicate hasLocationInfo(
481-
string filepath, int startline, int startcolumn, int endline, int endcolumn
482-
) {
483-
filepath = file.getAbsolutePath() and
484-
startline = 0 and
485-
startcolumn = 0 and
486-
endline = 0 and
487-
endcolumn = 0
488-
}
471+
override Location getLocation() { result = file.getLocation() }
489472

490473
/** Gets the module defined by the `script` tag in this .vue file, if any. */
491474
Module getModule() { result = getModuleFromVueFile(file) }
@@ -622,11 +605,7 @@ module Vue {
622605

623606
HtmlElement() { this = MkHtmlElement(elem) }
624607

625-
override predicate hasLocationInfo(
626-
string filepath, int startline, int startcolumn, int endline, int endcolumn
627-
) {
628-
elem.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
629-
}
608+
Location getLocation() { result = elem.getLocation() }
630609

631610
override string getName() { result = elem.getName() }
632611

javascript/ql/lib/utils/test/ConsistencyChecking.qll

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,18 @@ deprecated private DataFlow::Node alerts(Conf conf) {
9494
deprecated private DataFlow::Node getAlert(File file, int line, Conf conf) {
9595
result = alerts(conf) and
9696
result.getFile() = file and
97-
(result.hasLocationInfo(_, _, _, line, _) or result.hasLocationInfo(_, line, _, _, _))
97+
(
98+
result.getLocation().hasLocationInfo(_, _, _, line, _) or
99+
result.getLocation().hasLocationInfo(_, line, _, _, _)
100+
)
98101
or
99102
// The comment can be right above the result, so an alert also counts for the line above.
100103
not exists(Expr e |
101104
e.getFile() = file and [e.getLocation().getStartLine(), e.getLocation().getEndLine()] = line
102105
) and
103106
result = alerts(conf) and
104107
result.getFile() = file and
105-
result.hasLocationInfo(_, line + 1, _, _, _)
108+
result.getLocation().hasLocationInfo(_, line + 1, _, _, _)
106109
}
107110

108111
/**

javascript/ql/src/LanguageFeatures/InconsistentNew.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ predicate whitelistedCall(DataFlow::CallNode call) {
8888
DataFlow::InvokeNode getFirstInvocation(Function f, boolean isNew) {
8989
result =
9090
min(DataFlow::InvokeNode invk, string path, int line, int col |
91-
f = getALikelyCallee(invk, isNew) and invk.hasLocationInfo(path, line, col, _, _)
91+
f = getALikelyCallee(invk, isNew) and
92+
invk.getLocation().hasLocationInfo(path, line, col, _, _)
9293
|
9394
invk order by path, line, col
9495
)

javascript/ql/src/LanguageFeatures/SpuriousArguments.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class SpuriousArguments extends Expr {
7979
exists(DataFlow::Node lastArg |
8080
lastArg = max(DataFlow::Node arg, int i | arg = invk.getArgument(i) | arg order by i)
8181
|
82-
lastArg.hasLocationInfo(_, _, _, endline, endcolumn)
82+
lastArg.getLocation().hasLocationInfo(_, _, _, endline, endcolumn)
8383
)
8484
}
8585
}

javascript/ql/test/ApiGraphs/VerifyAssertions.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ private DataFlow::Node getNode(API::Node nd, string kind) {
2929

3030
private string getLoc(DataFlow::Node nd) {
3131
exists(string filepath, int startline |
32-
nd.hasLocationInfo(filepath, startline, _, _, _) and
32+
nd.getLocation().hasLocationInfo(filepath, startline, _, _, _) and
3333
result = filepath + ":" + startline
3434
)
3535
}

javascript/ql/test/library-tests/TypeTracking/TypeTracking.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ DataFlow::SourceNode trackNamedNode(DataFlow::TypeTracker t, string name) {
66
exists(Comment c, string f, int l |
77
f = c.getFile().getAbsolutePath() and
88
l = c.getLocation().getStartLine() and
9-
result.hasLocationInfo(f, l, _, _, _) and
9+
result.getLocation().hasLocationInfo(f, l, _, _, _) and
1010
name = c.getText().regexpFind("(?<=name: )\\S+", _, _)
1111
)
1212
or

0 commit comments

Comments
 (0)