Skip to content

Commit 8277d5c

Browse files
author
Max Schaefer
committed
JavaScript: Introduce convenience predicate for working with typed API-graph nodes.
1 parent 9206549 commit 8277d5c

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

javascript/ql/src/semmle/javascript/ApiGraphs.qll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,17 @@ module API {
286286
/** Gets a node corresponding to an export of module `m`. */
287287
Node moduleExport(string m) { result = Impl::MkModuleDef(m).(Node).getMember("exports") }
288288

289+
/** Provides helper predicates for accessing API-graph nodes. */
290+
module Node {
291+
/** Gets a node whose type has the given qualified name. */
292+
Node ofType(string moduleName, string exportedName) {
293+
exists(TypeName tn |
294+
tn.hasQualifiedName(moduleName, exportedName) and
295+
result = Impl::MkCanonicalNameUse(tn).(Node).getInstance()
296+
)
297+
}
298+
}
299+
289300
/**
290301
* An API entry point.
291302
*
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| mongodb | Collection | index.ts:14:3:14:17 | getCollection() |
2+
| mongoose | Model | index.ts:22:3:22:20 | getMongooseModel() |
3+
| mongoose | Query | index.ts:23:3:23:20 | getMongooseQuery() |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import javascript
2+
3+
from string mod, string tp
4+
select mod, tp, API::Node::ofType(mod, tp).getAnImmediateUse()

0 commit comments

Comments
 (0)