Skip to content

Commit a1731cc

Browse files
committed
JS: Factor out functionReturnType
1 parent db27f0d commit a1731cc

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,16 @@ module TypeResolution {
141141
)
142142
}
143143

144+
private predicate functionReturnType(Function func, Node returnType) {
145+
returnType = func.getReturnTypeAnnotation()
146+
or
147+
not exists(func.getReturnTypeAnnotation()) and
148+
exists(Function functionType |
149+
contextualType(func, trackFunctionType(functionType)) and
150+
returnType = functionType.getReturnTypeAnnotation()
151+
)
152+
}
153+
144154
private predicate contextualType(Node value, Node type) {
145155
exists(InvokeExpr call, Function target, int i |
146156
callTarget(call, target) and
@@ -150,15 +160,8 @@ module TypeResolution {
150160
or
151161
exists(Function lambda |
152162
not lambda.isAsyncOrGenerator() and
153-
value = lambda.getAReturnedExpr()
154-
|
155-
type = lambda.getReturnTypeAnnotation()
156-
or
157-
not exists(lambda.getReturnTypeAnnotation()) and
158-
exists(Function functionType |
159-
contextualType(lambda, trackFunctionType(functionType)) and
160-
type = functionType.getReturnTypeAnnotation()
161-
)
163+
value = lambda.getAReturnedExpr() and
164+
functionReturnType(lambda, type)
162165
)
163166
or
164167
exists(ObjectExpr object, Node objectType, Node host, string name |

0 commit comments

Comments
 (0)