@@ -9,68 +9,6 @@ private import semmle.javascript.internal.NameResolution::NameResolution
99 * Provides name resolution and propagates type information.
1010 */
1111module UnderlyingTypes {
12- /**
13- * Holds if `moduleName` appears to start with a package name, as opposed to a relative file import.
14- */
15- bindingset [ moduleName]
16- private predicate isExternalModuleName ( string moduleName ) {
17- not moduleName .regexpMatch ( "^(\\.|/).*" )
18- }
19-
20- bindingset [ name]
21- private string normalizeModuleName ( string name ) {
22- result =
23- name .regexpReplaceAll ( "^node:" , "" )
24- .regexpReplaceAll ( "\\.[jt]sx?$" , "" )
25- .regexpReplaceAll ( "/(index)?$" , "" )
26- }
27-
28- /**
29- * Holds if `node` is a reference to the given module, or a qualified name rooted in that module.
30- *
31- * If `qualifiedName` is empty, `node` refers to the module itself.
32- *
33- * If `mod` is the string `"global"`, `node` refers to a global access path.
34- */
35- predicate nodeRefersToModule ( Node node , string mod , string qualifiedName ) {
36- exists ( PathExpr path |
37- path = any ( Import imprt ) .getImportedPath ( ) or
38- path = any ( ReExportDeclaration e ) .getImportedPath ( )
39- |
40- node = path and
41- mod = normalizeModuleName ( path .getValue ( ) ) and
42- isExternalModuleName ( mod ) and
43- qualifiedName = ""
44- )
45- or
46- mod = "global" and
47- exists ( LocalNamespaceAccess access |
48- node = access and
49- not exists ( access .getLocalNamespaceName ( ) ) and
50- access .getName ( ) = qualifiedName
51- )
52- or
53- // Additionally track through bulk re-exports (`export * from 'mod`).
54- // These are normally handled by 'exportAs' which supports various shadowing rules,
55- // but has no effect when the ultimate re-exported module is not resolved to a Module.
56- // We propagate external module refs through bulk re-exports and ignore shadowing rules.
57- exists ( BulkReExportDeclaration reExport |
58- nodeRefersToModule ( reExport .getImportedPath ( ) , mod , qualifiedName ) and
59- node = reExport .getContainer ( )
60- )
61- or
62- exists ( Node mid |
63- nodeRefersToModule ( mid , mod , qualifiedName ) and
64- ValueFlow:: step ( mid , node )
65- )
66- or
67- exists ( Node mid , string prefix , string step |
68- nodeRefersToModule ( mid , mod , prefix ) and
69- readStep ( mid , step , node ) and
70- qualifiedName = append ( prefix , step )
71- )
72- }
73-
7412 private predicate subtypeStep ( Node node1 , Node node2 ) {
7513 exists ( ClassOrInterface cls |
7614 (
@@ -133,16 +71,6 @@ module UnderlyingTypes {
13371 )
13472 }
13573
136- bindingset [ a, b]
137- private string append ( string a , string b ) {
138- if b = "default"
139- then result = a
140- else (
141- ( if a = "" or b = "" then result = a + b else result = a + "." + b ) and
142- result .length ( ) < 100
143- )
144- }
145-
14674 predicate nodeHasUnderlyingType ( Node node , string mod , string name ) {
14775 nodeRefersToModule ( node , mod , name )
14876 or
0 commit comments