@@ -33,31 +33,25 @@ class NodeModule extends Module {
3333 * Gets an abstract value representing one or more values that may flow
3434 * into this module's `module.exports` property.
3535 */
36+ pragma [ noinline]
3637 DefiniteAbstractValue getAModuleExportsValue ( ) {
37- exists ( AbstractProperty moduleExports |
38- moduleExports .getBase ( ) .( AbstractModuleObject ) .getModule ( ) = this and
39- moduleExports .getPropertyName ( ) = "exports"
40- |
41- result = moduleExports .getAValue ( )
42- )
38+ result = getAModuleExportsProperty ( ) .getAValue ( )
39+ }
40+
41+ pragma [ noinline]
42+ private AbstractProperty getAModuleExportsProperty ( ) {
43+ result .getBase ( ) .( AbstractModuleObject ) .getModule ( ) = this and
44+ result .getPropertyName ( ) = "exports"
4345 }
4446
4547 /**
4648 * Gets an expression that is an alias for `module.exports`.
47- * For performance this predicate only computes relevant expressions.
49+ * For performance this predicate only computes relevant expressions (in `getAModuleExportsCandidate`) .
4850 * So if using this predicate - consider expanding the list of relevant expressions.
4951 */
50- pragma [ noinline]
51- DataFlow:: Node getAModuleExportsNode ( ) {
52- (
53- // A bit of manual magic
54- result = any ( DataFlow:: PropWrite w | exists ( w .getPropertyName ( ) ) ) .getBase ( )
55- or
56- result = DataFlow:: valueNode ( any ( PropAccess p | exists ( p .getPropertyName ( ) ) ) .getBase ( ) )
57- or
58- result = DataFlow:: valueNode ( any ( ObjectExpr obj ) )
59- ) and
60- result .analyze ( ) .getAValue ( ) = getAModuleExportsValue ( )
52+ DataFlow:: AnalyzedNode getAModuleExportsNode ( ) {
53+ result = getAModuleExportsCandidate ( ) and
54+ result .getAValue ( ) = getAModuleExportsValue ( )
6155 }
6256
6357 /** Gets a symbol exported by this module. */
@@ -148,6 +142,21 @@ class NodeModule extends Module {
148142 }
149143}
150144
145+ /**
146+ * Gets an expression that syntactically could be a alias for `module.exports`.
147+ * This predicate exists to reduce the size of `getAModuleExportsNode`,
148+ * while keeping all the tuples that could be relevant in later computations.
149+ */
150+ pragma [ noinline]
151+ private DataFlow:: Node getAModuleExportsCandidate ( ) {
152+ // A bit of manual magic
153+ result = any ( DataFlow:: PropWrite w | exists ( w .getPropertyName ( ) ) ) .getBase ( )
154+ or
155+ result = DataFlow:: valueNode ( any ( PropAccess p | exists ( p .getPropertyName ( ) ) ) .getBase ( ) )
156+ or
157+ result = DataFlow:: valueNode ( any ( ObjectExpr obj ) )
158+ }
159+
151160/**
152161 * Holds if `nodeModules` is a folder of the form `<prefix>/node_modules`, where
153162 * `<prefix>` is a (not necessarily proper) prefix of `f` and does not end in `/node_modules`,
0 commit comments