@@ -37,24 +37,34 @@ class NodeModule extends Module {
3737 * into this module's `module.exports` property.
3838 */
3939 pragma [ noinline]
40- DefiniteAbstractValue getAModuleExportsValue ( ) {
41- result = this .getAModuleExportsProperty ( ) .getAValue ( )
40+ deprecated DefiniteAbstractValue getAModuleExportsValue ( ) { none ( ) }
41+
42+ /**
43+ * Gets the `SourceNode` corresponding to the value of `module`.
44+ */
45+ private DataFlow:: SourceNode getModuleSourceNode ( ) {
46+ result = DataFlow:: ssaDefinitionNode ( Ssa:: implicitInit ( this .getModuleVariable ( ) ) )
4247 }
4348
44- pragma [ noinline]
45- private AbstractProperty getAModuleExportsProperty ( ) {
46- result .getBase ( ) .( AbstractModuleObject ) .getModule ( ) = this and
47- result .getPropertyName ( ) = "exports"
49+ /**
50+ * Gets a `SourceNode` corresponding to the initial value of `module.exports` or
51+ * anything assigned to `module.exports`.
52+ */
53+ private DataFlow:: SourceNode getExportsSourceNode ( ) {
54+ result = DataFlow:: ssaDefinitionNode ( Ssa:: implicitInit ( this .getExportsVariable ( ) ) )
55+ or
56+ result = this .getModuleSourceNode ( ) .getAPropertyWrite ( "exports" ) .getRhs ( ) .getALocalSource ( )
57+ or
58+ result = this .getModuleSourceNode ( ) .getAPropertyRead ( "exports" )
4859 }
4960
5061 /**
5162 * Gets an expression that is an alias for `module.exports`.
5263 * For performance this predicate only computes relevant expressions (in `getAModuleExportsCandidate`).
5364 * So if using this predicate - consider expanding the list of relevant expressions.
5465 */
55- DataFlow:: AnalyzedNode getAModuleExportsNode ( ) {
56- result = getAModuleExportsCandidate ( ) and
57- result .getAValue ( ) = this .getAModuleExportsValue ( )
66+ deprecated DataFlow:: AnalyzedNode getAModuleExportsNode ( ) {
67+ result = this .getExportsSourceNode ( ) .getALocalUse ( )
5868 }
5969
6070 /** Gets a symbol exported by this module. */
@@ -64,21 +74,15 @@ class NodeModule extends Module {
6474 result = this .getAnImplicitlyExportedSymbol ( )
6575 or
6676 // getters and the like.
67- exists ( DataFlow:: PropWrite pwn |
68- pwn .getBase ( ) = this .getAModuleExportsNode ( ) and
69- result = pwn .getPropertyName ( )
70- )
77+ result = this .getExportsSourceNode ( ) .getAPropertyWrite ( ) .getPropertyName ( )
7178 }
7279
7380 override DataFlow:: Node getAnExportedValue ( string name ) {
7481 // a property write whose base is `exports` or `module.exports`
75- exists ( DataFlow:: PropWrite pwn | result = pwn .getRhs ( ) |
76- pwn .getBase ( ) = this .getAModuleExportsNode ( ) and
77- name = pwn .getPropertyName ( )
78- )
82+ result = this .getExportsSourceNode ( ) .getAPropertyWrite ( name ) .getRhs ( )
7983 or
8084 // a re-export using spread-operator. E.g. `const foo = require("./foo"); module.exports = {bar: bar, ...foo};`
81- exists ( ObjectExpr obj | obj = this .getAModuleExportsNode ( ) .asExpr ( ) |
85+ exists ( ObjectExpr obj | obj = this .getExportsSourceNode ( ) .asExpr ( ) |
8286 result =
8387 obj .getAProperty ( )
8488 .( SpreadProperty )
@@ -99,16 +103,15 @@ class NodeModule extends Module {
99103 // }
100104 exists ( DynamicPropertyAccess:: EnumeratedPropName read , Import imp , DataFlow:: PropWrite write |
101105 read .getSourceObject ( ) .getALocalSource ( ) .asExpr ( ) = imp and
106+ write = this .getExportsSourceNode ( ) .getAPropertyWrite ( ) and
102107 getASourceProp ( read ) = write .getRhs ( ) and
103- write .getBase ( ) = this .getAModuleExportsNode ( ) and
104108 write .getPropertyNameExpr ( ) .flow ( ) .getImmediatePredecessor * ( ) = read and
105109 result = imp .getImportedModule ( ) .getAnExportedValue ( name )
106110 )
107111 or
108112 // an externs definition (where appropriate)
109113 exists ( PropAccess pacc | result = DataFlow:: valueNode ( pacc ) |
110- pacc .getBase ( ) = this .getAModuleExportsNode ( ) .asExpr ( ) and
111- name = pacc .getPropertyName ( ) and
114+ pacc = this .getExportsSourceNode ( ) .getAPropertyRead ( name ) .asExpr ( ) and
112115 this .isExterns ( ) and
113116 exists ( pacc .getDocumentation ( ) )
114117 )
0 commit comments