Skip to content

Commit 646639b

Browse files
authored
Merge pull request github#5460 from erik-krogh/forgery-2
Approved by asgerf
2 parents 3cfd30e + cd57e61 commit 646639b

File tree

1 file changed

+8
-27
lines changed

1 file changed

+8
-27
lines changed

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

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ module API {
313313
module Node {
314314
/** Gets a node whose type has the given qualified name. */
315315
Node ofType(string moduleName, string exportedName) {
316-
result = Impl::MkHasUnderlyingType(moduleName, exportedName).(Node).getInstance()
316+
result = Impl::MkTypeUse(moduleName, exportedName).(Node).getInstance()
317317
}
318318
}
319319

@@ -374,27 +374,22 @@ module API {
374374
exists(SSA::implicitInit([nm.getModuleVariable(), nm.getExportsVariable()]))
375375
)
376376
)
377-
or
378-
m = any(CanonicalName n | isDefined(n)).getExternalModuleName()
379377
} or
380378
MkModuleImport(string m) {
381379
imports(_, m)
382380
or
383-
m = any(CanonicalName n | isUsed(n)).getExternalModuleName()
384-
or
385381
any(TypeAnnotation n).hasQualifiedName(m, _)
382+
or
383+
any(Type t).hasUnderlyingType(m, _)
386384
} or
387385
MkClassInstance(DataFlow::ClassNode cls) { cls = trackDefNode(_) and hasSemantics(cls) } or
388386
MkAsyncFuncResult(DataFlow::FunctionNode f) {
389387
f = trackDefNode(_) and f.getFunction().isAsync() and hasSemantics(f)
390388
} or
391389
MkDef(DataFlow::Node nd) { rhs(_, _, nd) } or
392390
MkUse(DataFlow::Node nd) { use(_, _, nd) } or
393-
/**
394-
* A TypeScript type, identified by name of the type-annotation.
395-
* This API node is exclusively used by `API::Node::ofType`.
396-
*/
397-
MkHasUnderlyingType(string moduleName, string exportName) {
391+
/** A use of a TypeScript type. */
392+
MkTypeUse(string moduleName, string exportName) {
398393
any(TypeAnnotation n).hasQualifiedName(moduleName, exportName)
399394
or
400395
any(Type t).hasUnderlyingType(moduleName, exportName)
@@ -408,7 +403,7 @@ module API {
408403
class TNonModuleDef =
409404
MkModuleExport or MkClassInstance or MkAsyncFuncResult or MkDef or MkSyntheticCallbackArg;
410405

411-
class TUse = MkModuleUse or MkModuleImport or MkUse or MkHasUnderlyingType;
406+
class TUse = MkModuleUse or MkModuleImport or MkUse or MkTypeUse;
412407

413408
private predicate hasSemantics(DataFlow::Node nd) { not nd.getTopLevel().isExterns() }
414409

@@ -431,20 +426,6 @@ module API {
431426
)
432427
}
433428

434-
private predicate isUsed(CanonicalName n) {
435-
exists(n.(TypeName).getAnAccess()) or
436-
exists(n.(Namespace).getAnAccess())
437-
}
438-
439-
private predicate isDefined(CanonicalName n) {
440-
exists(ASTNode def |
441-
def = n.(TypeName).getADefinition() or
442-
def = n.(Namespace).getADefinition()
443-
|
444-
not def.isAmbient()
445-
)
446-
}
447-
448429
/**
449430
* Holds if `rhs` is the right-hand side of a definition of a node that should have an
450431
* incoming edge from `base` labeled `lbl` in the API graph.
@@ -600,7 +581,7 @@ module API {
600581
)
601582
or
602583
exists(string moduleName, string exportName |
603-
base = MkHasUnderlyingType(moduleName, exportName) and
584+
base = MkTypeUse(moduleName, exportName) and
604585
lbl = Label::instance() and
605586
ref.(DataFlow::SourceNode).hasUnderlyingType(moduleName, exportName)
606587
)
@@ -839,7 +820,7 @@ module API {
839820
exists(string moduleName, string exportName |
840821
pred = MkModuleImport(moduleName) and
841822
lbl = Label::member(exportName) and
842-
succ = MkHasUnderlyingType(moduleName, exportName)
823+
succ = MkTypeUse(moduleName, exportName)
843824
)
844825
or
845826
exists(DataFlow::Node nd, DataFlow::FunctionNode f |

0 commit comments

Comments
 (0)