File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed
javascript/ql/lib/semmle/javascript Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -229,7 +229,10 @@ module DataFlow {
229
229
predicate hasUnderlyingType ( string globalName ) {
230
230
Stages:: TypeTracking:: ref ( ) and
231
231
exists ( NameResolution:: Node type |
232
- TypeResolution:: valueHasType ( this .getNameResolutionNode ( ) , type ) and
232
+ TypeResolution:: valueHasType ( this .getNameResolutionNode ( ) , type )
233
+ or
234
+ TypeResolution:: contextualType ( this .getNameResolutionNode ( ) , type )
235
+ |
233
236
UnderlyingTypes:: nodeHasUnderlyingType ( type , globalName )
234
237
)
235
238
}
@@ -243,7 +246,12 @@ module DataFlow {
243
246
Stages:: TypeTracking:: ref ( ) and
244
247
moduleName != "global" and
245
248
exists ( NameResolution:: Node type |
246
- TypeResolution:: valueHasType ( this .getNameResolutionNode ( ) , type ) and
249
+ TypeResolution:: valueHasType ( this .getNameResolutionNode ( ) , type )
250
+ or
251
+ // Also check contextual type as this helps when tracking facts between SourceNode only.
252
+ // For example, for `var x: T = getFoo()` we need `getFoo()` to have the type T.
253
+ TypeResolution:: contextualType ( this .getNameResolutionNode ( ) , type )
254
+ |
247
255
UnderlyingTypes:: nodeHasUnderlyingType ( type , moduleName , typeName )
248
256
)
249
257
}
Original file line number Diff line number Diff line change @@ -170,7 +170,12 @@ module TypeResolution {
170
170
)
171
171
}
172
172
173
- private predicate contextualType ( Node value , Node type ) {
173
+ predicate contextualType ( Node value , Node type ) {
174
+ exists ( LocalVariable v |
175
+ type = v .getADeclaration ( ) .getTypeAnnotation ( ) and
176
+ value = v .getAnAssignedExpr ( )
177
+ )
178
+ or
174
179
exists ( InvokeExpr call , Function target , int i |
175
180
callTarget ( call , target ) and
176
181
value = call .getArgument ( i ) and
You can’t perform that action at this time.
0 commit comments