@@ -27,6 +27,9 @@ private import internal.PreCallGraphStep
2727private import semmle.javascript.internal.CachedStages
2828private import semmle.javascript.dataflow.internal.DataFlowPrivate as Private
2929private 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
3033
3134module DataFlow {
3235 /**
@@ -189,26 +192,6 @@ module DataFlow {
189192 FlowSteps:: identityFunctionStep ( result , this )
190193 }
191194
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-
212195 /**
213196 * Gets the type annotation describing the type of this node,
214197 * provided that a static type could not be found.
@@ -229,16 +212,26 @@ module DataFlow {
229212 )
230213 }
231214
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+
232224 /**
233225 * Holds if this node is annotated with the given named type,
234226 * or is declared as a subtype thereof, or is a union or intersection containing such a type.
235227 */
236228 cached
237229 predicate hasUnderlyingType ( string globalName ) {
238230 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+ )
242235 }
243236
244237 /**
@@ -248,9 +241,11 @@ module DataFlow {
248241 cached
249242 predicate hasUnderlyingType ( string moduleName , string typeName ) {
250243 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+ )
254249 }
255250
256251 /**
0 commit comments