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 {
229229 predicate hasUnderlyingType ( string globalName ) {
230230 Stages:: TypeTracking:: ref ( ) and
231231 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+ |
233236 UnderlyingTypes:: nodeHasUnderlyingType ( type , globalName )
234237 )
235238 }
@@ -243,7 +246,12 @@ module DataFlow {
243246 Stages:: TypeTracking:: ref ( ) and
244247 moduleName != "global" and
245248 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+ |
247255 UnderlyingTypes:: nodeHasUnderlyingType ( type , moduleName , typeName )
248256 )
249257 }
Original file line number Diff line number Diff line change @@ -170,7 +170,12 @@ module TypeResolution {
170170 )
171171 }
172172
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
174179 exists ( InvokeExpr call , Function target , int i |
175180 callTarget ( call , target ) and
176181 value = call .getArgument ( i ) and
You can’t perform that action at this time.
0 commit comments