@@ -313,10 +313,7 @@ module API {
313313 module Node {
314314 /** Gets a node whose type has the given qualified name. */
315315 Node ofType ( string moduleName , string exportedName ) {
316- exists ( TypeName tn |
317- tn .hasQualifiedName ( moduleName , exportedName ) and
318- result = Impl:: MkCanonicalNameUse ( tn ) .( Node ) .getInstance ( )
319- )
316+ result = Impl:: MkHasUnderlyingType ( moduleName , exportedName ) .( Node ) .getInstance ( )
320317 }
321318 }
322319
@@ -384,6 +381,8 @@ module API {
384381 imports ( _, m )
385382 or
386383 m = any ( CanonicalName n | isUsed ( n ) ) .getExternalModuleName ( )
384+ or
385+ any ( TypeAnnotation n ) .hasQualifiedName ( m , _)
387386 } or
388387 MkClassInstance ( DataFlow:: ClassNode cls ) { cls = trackDefNode ( _) and hasSemantics ( cls ) } or
389388 MkAsyncFuncResult ( DataFlow:: FunctionNode f ) {
@@ -392,26 +391,13 @@ module API {
392391 MkDef ( DataFlow:: Node nd ) { rhs ( _, _, nd ) } or
393392 MkUse ( DataFlow:: Node nd ) { use ( _, _, nd ) } or
394393 /**
395- * A TypeScript canonical name that is defined somewhere, and that isn't a module root.
396- * (Module roots are represented by `MkModuleExport` nodes instead.)
397- *
398- * For most purposes, you probably want to use the `mkCanonicalNameDef` predicate instead of
399- * this constructor.
400- */
401- MkCanonicalNameDef ( CanonicalName n ) {
402- not n .isRoot ( ) and
403- isDefined ( n )
404- } or
405- /**
406- * A TypeScript canonical name that is used somewhere, and that isn't a module root.
407- * (Module roots are represented by `MkModuleImport` nodes instead.)
408- *
409- * For most purposes, you probably want to use the `mkCanonicalNameUse` predicate instead of
410- * this constructor.
394+ * A TypeScript type, identified by name of the type-annotation.
395+ * This API node is exclusively used by `API::Node::ofType`.
411396 */
412- MkCanonicalNameUse ( CanonicalName n ) {
413- not n .isRoot ( ) and
414- isUsed ( n )
397+ MkHasUnderlyingType ( string moduleName , string exportName ) {
398+ any ( TypeAnnotation n ) .hasQualifiedName ( moduleName , exportName )
399+ or
400+ any ( Type t ) .hasUnderlyingType ( moduleName , exportName )
415401 } or
416402 MkSyntheticCallbackArg ( DataFlow:: Node src , int bound , DataFlow:: InvokeNode nd ) {
417403 trackUseNode ( src , true , bound ) .flowsTo ( nd .getCalleeNode ( ) )
@@ -420,10 +406,9 @@ module API {
420406 class TDef = MkModuleDef or TNonModuleDef ;
421407
422408 class TNonModuleDef =
423- MkModuleExport or MkClassInstance or MkAsyncFuncResult or MkDef or MkCanonicalNameDef or
424- MkSyntheticCallbackArg ;
409+ MkModuleExport or MkClassInstance or MkAsyncFuncResult or MkDef or MkSyntheticCallbackArg ;
425410
426- class TUse = MkModuleUse or MkModuleImport or MkUse or MkCanonicalNameUse ;
411+ class TUse = MkModuleUse or MkModuleImport or MkUse or MkHasUnderlyingType ;
427412
428413 private predicate hasSemantics ( DataFlow:: Node nd ) { not nd .getTopLevel ( ) .isExterns ( ) }
429414
@@ -460,20 +445,6 @@ module API {
460445 )
461446 }
462447
463- /** An API-graph node representing definitions of the canonical name `cn`. */
464- private TApiNode mkCanonicalNameDef ( CanonicalName cn ) {
465- if cn .isModuleRoot ( )
466- then result = MkModuleExport ( cn .getExternalModuleName ( ) )
467- else result = MkCanonicalNameDef ( cn )
468- }
469-
470- /** An API-graph node representing uses of the canonical name `cn`. */
471- private TApiNode mkCanonicalNameUse ( CanonicalName cn ) {
472- if cn .isModuleRoot ( )
473- then result = MkModuleImport ( cn .getExternalModuleName ( ) )
474- else result = MkCanonicalNameUse ( cn )
475- }
476-
477448 /**
478449 * Holds if `rhs` is the right-hand side of a definition of a node that should have an
479450 * incoming edge from `base` labeled `lbl` in the API graph.
@@ -577,11 +548,6 @@ module API {
577548 exists ( string m | nd = MkModuleExport ( m ) | exports ( m , rhs ) )
578549 or
579550 nd = MkDef ( rhs )
580- or
581- exists ( CanonicalName n | nd = MkCanonicalNameDef ( n ) |
582- rhs = n .( Namespace ) .getADefinition ( ) .flow ( ) or
583- rhs = n .( CanonicalFunctionName ) .getADefinition ( ) .flow ( )
584- )
585551 }
586552
587553 /**
@@ -633,10 +599,10 @@ module API {
633599 ref = cls .getConstructor ( ) .getParameter ( i )
634600 )
635601 or
636- exists ( TypeName tn |
637- base = MkCanonicalNameUse ( tn ) and
602+ exists ( string moduleName , string exportName |
603+ base = MkHasUnderlyingType ( moduleName , exportName ) and
638604 lbl = Label:: instance ( ) and
639- ref = getANodeWithType ( tn )
605+ ref . ( DataFlow :: SourceNode ) . hasUnderlyingType ( moduleName , exportName )
640606 )
641607 or
642608 exists ( DataFlow:: InvokeNode call |
@@ -676,8 +642,6 @@ module API {
676642 )
677643 or
678644 nd = MkUse ( ref )
679- or
680- exists ( CanonicalName n | nd = MkCanonicalNameUse ( n ) | ref .asExpr ( ) = n .getAnAccess ( ) )
681645 }
682646
683647 /** Holds if module `m` exports `rhs`. */
@@ -832,13 +796,6 @@ module API {
832796 result = awaited ( call , DataFlow:: TypeTracker:: end ( ) )
833797 }
834798
835- private DataFlow:: SourceNode getANodeWithType ( TypeName tn ) {
836- exists ( string moduleName , string typeName |
837- tn .hasQualifiedName ( moduleName , typeName ) and
838- result .hasUnderlyingType ( moduleName , typeName )
839- )
840- }
841-
842799 /**
843800 * Holds if there is an edge from `pred` to `succ` in the API graph that is labeled with `lbl`.
844801 */
@@ -879,11 +836,10 @@ module API {
879836 succ = MkClassInstance ( trackDefNode ( def ) )
880837 )
881838 or
882- exists ( CanonicalName cn1 , string n , CanonicalName cn2 |
883- pred in [ mkCanonicalNameDef ( cn1 ) , mkCanonicalNameUse ( cn1 ) ] and
884- cn2 = cn1 .getChild ( n ) and
885- lbl = Label:: member ( n ) and
886- succ in [ mkCanonicalNameDef ( cn2 ) , mkCanonicalNameUse ( cn2 ) ]
839+ exists ( string moduleName , string exportName |
840+ pred = MkModuleImport ( moduleName ) and
841+ lbl = Label:: member ( exportName ) and
842+ succ = MkHasUnderlyingType ( moduleName , exportName )
887843 )
888844 or
889845 exists ( DataFlow:: Node nd , DataFlow:: FunctionNode f |
0 commit comments