@@ -27,6 +27,9 @@ private import internal.PreCallGraphStep
27
27
private import semmle.javascript.internal.CachedStages
28
28
private import semmle.javascript.dataflow.internal.DataFlowPrivate as Private
29
29
private import semmle.javascript.dataflow.internal.VariableOrThis
30
+ private import semmle.javascript.internal.NameResolution
31
+ private import semmle.javascript.internal.UnderlyingTypes
32
+ private import semmle.javascript.internal.TypeResolution
30
33
31
34
module DataFlow {
32
35
/**
@@ -189,26 +192,6 @@ module DataFlow {
189
192
FlowSteps:: identityFunctionStep ( result , this )
190
193
}
191
194
192
- /**
193
- * Gets the static type of this node as determined by the TypeScript type system.
194
- */
195
- private Type getType ( ) {
196
- exists ( AST:: ValueNode node |
197
- this = TValueNode ( node ) and
198
- ast_node_type ( node , result )
199
- )
200
- or
201
- exists ( BindingPattern pattern |
202
- this = lvalueNode ( pattern ) and
203
- ast_node_type ( pattern , result )
204
- )
205
- or
206
- exists ( MethodDefinition def |
207
- this = TThisNode ( def .getInit ( ) ) and
208
- ast_node_type ( def .getDeclaringClass ( ) , result )
209
- )
210
- }
211
-
212
195
/**
213
196
* Gets the type annotation describing the type of this node,
214
197
* provided that a static type could not be found.
@@ -229,16 +212,26 @@ module DataFlow {
229
212
)
230
213
}
231
214
215
+ private NameResolution:: Node getNameResolutionNode ( ) {
216
+ this = valueNode ( result )
217
+ or
218
+ exists ( PropertyPattern pattern |
219
+ result = pattern .getValuePattern ( ) and
220
+ this = TPropNode ( pattern )
221
+ )
222
+ }
223
+
232
224
/**
233
225
* Holds if this node is annotated with the given named type,
234
226
* or is declared as a subtype thereof, or is a union or intersection containing such a type.
235
227
*/
236
228
cached
237
229
predicate hasUnderlyingType ( string globalName ) {
238
230
Stages:: TypeTracking:: ref ( ) and
239
- this .getType ( ) .hasUnderlyingType ( globalName )
240
- or
241
- this .getFallbackTypeAnnotation ( ) .getAnUnderlyingType ( ) .hasQualifiedName ( globalName )
231
+ exists ( NameResolution:: Node type |
232
+ TypeResolution:: valueHasType ( this .getNameResolutionNode ( ) , type ) and
233
+ UnderlyingTypes:: nodeHasUnderlyingType ( type , "global" , globalName )
234
+ )
242
235
}
243
236
244
237
/**
@@ -248,9 +241,11 @@ module DataFlow {
248
241
cached
249
242
predicate hasUnderlyingType ( string moduleName , string typeName ) {
250
243
Stages:: TypeTracking:: ref ( ) and
251
- this .getType ( ) .hasUnderlyingType ( moduleName , typeName )
252
- or
253
- this .getFallbackTypeAnnotation ( ) .getAnUnderlyingType ( ) .hasQualifiedName ( moduleName , typeName )
244
+ moduleName != "global" and
245
+ exists ( NameResolution:: Node type |
246
+ TypeResolution:: valueHasType ( this .getNameResolutionNode ( ) , type ) and
247
+ UnderlyingTypes:: nodeHasUnderlyingType ( type , moduleName , typeName )
248
+ )
254
249
}
255
250
256
251
/**
0 commit comments