@@ -6,8 +6,11 @@ import javascript
6
6
7
7
module LazyCache {
8
8
/**
9
+ * DEPRECATED. DO NOT USE.
10
+ *
9
11
* A lazy-cache object, usually created through an expression of form `require('lazy-cache')(require)`.
10
12
*/
13
+ deprecated
11
14
class LazyCacheObject extends DataFlow:: SourceNode {
12
15
LazyCacheObject ( ) {
13
16
// Use `require` directly instead of `moduleImport` to avoid recursion.
@@ -19,13 +22,26 @@ module LazyCache {
19
22
}
20
23
}
21
24
25
+ /**
26
+ * A variable containing a lazy-cache object.
27
+ */
28
+ class LazyCacheVariable extends LocalVariable {
29
+ LazyCacheVariable ( ) {
30
+ // To avoid recursion, this should not depend on `SourceNode`.
31
+ exists ( Require req |
32
+ req .getArgument ( 0 ) .getStringValue ( ) = "lazy-cache" and
33
+ getAnAssignedExpr ( ) .( CallExpr ) .getCallee ( ) = req
34
+ )
35
+ }
36
+ }
37
+
22
38
/**
23
39
* An import through `lazy-cache`.
24
40
*/
25
41
class LazyCacheImport extends CallExpr , Import {
26
- LazyCacheObject cache ;
42
+ LazyCacheVariable cache ;
27
43
28
- LazyCacheImport ( ) { this = cache .getACall ( ) . asExpr ( ) }
44
+ LazyCacheImport ( ) { getCallee ( ) = cache .getAnAccess ( ) }
29
45
30
46
/** Gets the name of the package as it's exposed on the lazy-cache object. */
31
47
string getLocalAlias ( ) {
@@ -39,10 +55,23 @@ module LazyCache {
39
55
40
56
override PathExpr getImportedPath ( ) { result = getArgument ( 0 ) }
41
57
58
+ private LazyCacheVariable getVariable ( ) {
59
+ result = cache
60
+ }
61
+
62
+ pragma [ noopt]
42
63
override DataFlow:: Node getImportedModuleNode ( ) {
64
+ this instanceof LazyCacheImport and
43
65
result = this .flow ( )
44
66
or
45
- result = cache .getAPropertyRead ( getLocalAlias ( ) )
67
+ exists ( LazyCacheVariable variable , Expr base , PropAccess access , string localName |
68
+ variable = getVariable ( ) and
69
+ base = variable .getAnAccess ( ) and
70
+ access .getBase ( ) = base and
71
+ localName = getLocalAlias ( ) and
72
+ access .getPropertyName ( ) = localName and
73
+ result = access .flow ( )
74
+ )
46
75
}
47
76
}
48
77
0 commit comments