Skip to content

Commit 4ba8e1f

Browse files
committed
JS: Fix handling of typeof
1 parent 83f55db commit 4ba8e1f

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

javascript/ql/lib/semmle/javascript/internal/TypeResolution.qll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ module TypeResolution {
126126
node1 = fun.getFunction() and
127127
node2 = fun
128128
)
129+
or
130+
exists(TypeofTypeExpr type |
131+
node1 = type.getExpressionName() and
132+
node2 = type
133+
)
129134
}
130135

131136
/**
@@ -144,6 +149,12 @@ module TypeResolution {
144149
node2 = access
145150
)
146151
or
152+
exists(QualifiedVarTypeAccess access |
153+
node1 = access.getQualifier() and
154+
name = access.getIdentifier().getName() and
155+
node2 = access
156+
)
157+
or
147158
exists(PropAccess access |
148159
node1 = access.getBase() and
149160
name = access.getPropertyName() and

javascript/ql/lib/semmle/javascript/internal/UnderlyingTypes.qll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ module UnderlyingTypes {
6262
exists(Node mid |
6363
nodeRefersToModule(mid, mod, qualifiedName) and
6464
ValueFlow::step(mid, node) and
65-
not node instanceof Variable // avoid a lot of unnecessary tuples
65+
// avoid a lot of unnecessary tuples
66+
not (
67+
node instanceof Variable and
68+
not node = any(LocalVarTypeAccess ac).getVariable() // needed for TypeofTypeExpr
69+
)
6670
)
6771
or
6872
exists(Node mid, string prefix, string step |
@@ -145,11 +149,7 @@ module UnderlyingTypes {
145149
}
146150

147151
predicate nodeHasUnderlyingType(Node node, string mod, string name) {
148-
exists(Node mid, string prefix, string step |
149-
nodeRefersToModule(mid, mod, prefix) and
150-
readStep(mid, step, node) and
151-
name = append(prefix, step)
152-
)
152+
nodeRefersToModule(node, mod, name)
153153
or
154154
exists(JSDocNamedTypeExpr type |
155155
node = type and

javascript/ql/test/library-tests/UnderlyingTypes/expressWrapperExport.use.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ function t7(req: w.Request) { // none
2424

2525
function t8(res: w.Response) { // none
2626
}
27+
28+
function t9(e: typeof w.wrapper) { // $ hasUnderlyingType='express'
29+
}

javascript/ql/test/library-tests/UnderlyingTypes/namespaceImport.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as express from 'express';
22

3-
function t1(e: typeof express) { // $ MISSING: hasUnderlyingType='express'
3+
function t1(e: typeof express) { // $ hasUnderlyingType='express'
44
}
55

66
function t2(req: express.Request) { // $ hasUnderlyingType='express'.Request

0 commit comments

Comments
 (0)