Skip to content

Commit 5e2a1ad

Browse files
committed
JS: Deprecate getAnExportedSymbol() and DubiousImport.ql
getAnExportedSymbol() has a complex implementation that I'd rather not want to migrate given that it's only used by a dead query.
1 parent eac06af commit 5e2a1ad

File tree

7 files changed

+2
-178
lines changed

7 files changed

+2
-178
lines changed

javascript/ql/integration-tests/query-suite/not_included_in_qls.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ ql/javascript/ql/src/Metrics/FUseOfES6.ql
4444
ql/javascript/ql/src/Metrics/FunCyclomaticComplexity.ql
4545
ql/javascript/ql/src/Metrics/FunLinesOfCode.ql
4646
ql/javascript/ql/src/NodeJS/CyclicImport.ql
47-
ql/javascript/ql/src/NodeJS/DubiousImport.ql
4847
ql/javascript/ql/src/NodeJS/UnresolvableImport.ql
4948
ql/javascript/ql/src/NodeJS/UnusedDependency.ql
5049
ql/javascript/ql/src/Performance/NonLocalForIn.ql

javascript/ql/lib/semmle/javascript/Modules.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ abstract class Module extends TopLevel {
2525
/** Gets a module from which this module imports. */
2626
Module getAnImportedModule() { result = this.getAnImport().getImportedModule() }
2727

28-
/** Gets a symbol exported by this module. */
29-
string getAnExportedSymbol() { exists(this.getAnExportedValue(result)) }
28+
/** DEPRECATED. Use `exists(getAnExportedValue(name))` instead. */
29+
deprecated string getAnExportedSymbol() { exists(this.getAnExportedValue(result)) }
3030

3131
/**
3232
* Get a value that is explicitly exported from this module with under `name`.

javascript/ql/lib/semmle/javascript/NodeJS.qll

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,6 @@ class NodeModule extends Module {
6767
result = this.getExportsSourceNode().getALocalUse()
6868
}
6969

70-
/** Gets a symbol exported by this module. */
71-
override string getAnExportedSymbol() {
72-
result = super.getAnExportedSymbol()
73-
or
74-
result = this.getAnImplicitlyExportedSymbol()
75-
or
76-
// getters and the like.
77-
result = this.getExportsSourceNode().getAPropertyWrite().getPropertyName()
78-
}
79-
8070
override DataFlow::Node getAnExportedValue(string name) {
8171
// a property write whose base is `exports` or `module.exports`
8272
result = this.getExportsSourceNode().getAPropertyWrite(name).getRhs()
@@ -126,29 +116,6 @@ class NodeModule extends Module {
126116
)
127117
}
128118

129-
/** Gets a symbol that the module object inherits from its prototypes. */
130-
private string getAnImplicitlyExportedSymbol() {
131-
exists(ExternalConstructor ec | ec = this.getPrototypeOfExportedExpr() |
132-
result = ec.getAMember().getName()
133-
or
134-
ec instanceof FunctionExternal and result = "prototype"
135-
or
136-
ec instanceof ArrayExternal and
137-
exists(NumberLiteral nl | result = nl.getValue() and exists(result.toInt()))
138-
)
139-
}
140-
141-
/** Gets an externs declaration of the prototype object of a value exported by this module. */
142-
private ExternalConstructor getPrototypeOfExportedExpr() {
143-
exists(AbstractValue exported | exported = this.getAModuleExportsValue() |
144-
result instanceof ObjectExternal
145-
or
146-
exported instanceof AbstractFunction and result instanceof FunctionExternal
147-
or
148-
exported instanceof AbstractOtherObject and result instanceof ArrayExternal
149-
)
150-
}
151-
152119
deprecated override predicate searchRoot(PathExpr path, Folder searchRoot, int priority) {
153120
path.getEnclosingModule() = this and
154121
exists(string pathval | pathval = path.getValue() |
@@ -184,21 +151,6 @@ private DataFlow::SourceNode getASourceProp(DynamicPropertyAccess::EnumeratedPro
184151
)
185152
}
186153

187-
/**
188-
* Gets an expression that syntactically could be a alias for `module.exports`.
189-
* This predicate exists to reduce the size of `getAModuleExportsNode`,
190-
* while keeping all the tuples that could be relevant in later computations.
191-
*/
192-
pragma[noinline]
193-
private DataFlow::Node getAModuleExportsCandidate() {
194-
// A bit of manual magic
195-
result = any(DataFlow::PropWrite w).getBase()
196-
or
197-
result = DataFlow::valueNode(any(PropAccess p | exists(p.getPropertyName())).getBase())
198-
or
199-
result = DataFlow::valueNode(any(ObjectExpr obj))
200-
}
201-
202154
/**
203155
* Holds if `nodeModules` is a folder of the form `<prefix>/node_modules`, where
204156
* `<prefix>` is a (not necessarily proper) prefix of `f` and does not end in `/node_modules`,

javascript/ql/src/NodeJS/DubiousImport.qhelp

Lines changed: 0 additions & 47 deletions
This file was deleted.

javascript/ql/src/NodeJS/DubiousImport.ql

Lines changed: 0 additions & 68 deletions
This file was deleted.

javascript/ql/test/library-tests/NodeJS/tests.expected

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
module_getAnExportedSymbol
2-
| b.js:1:1:8:0 | <toplevel> | sneaky |
3-
| d.js:1:1:7:15 | <toplevel> | baz |
4-
| reexport/a.js:1:1:3:1 | <toplevel> | foo |
5-
| reexport/b.js:1:1:6:1 | <toplevel> | bar |
6-
| reexport/b.js:1:1:6:1 | <toplevel> | foo |
7-
| sub/c.js:1:1:4:0 | <toplevel> | foo |
8-
| sub/f.js:1:1:4:17 | <toplevel> | bar |
91
module_getAnImport
102
| a.js:1:1:14:0 | <toplevel> | a.js:1:9:1:22 | require('./b') |
113
| a.js:1:1:14:0 | <toplevel> | a.js:2:7:2:19 | require('fs') |

javascript/ql/test/library-tests/NodeJS/tests.ql

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import javascript
22

3-
query predicate module_getAnExportedSymbol(NodeModule m, string symbol) {
4-
symbol = m.getAnExportedSymbol()
5-
}
6-
73
query predicate module_getAnImport(NodeModule m, Import imp) { imp = m.getAnImport() }
84

95
query predicate module_getAnImportedModule(NodeModule m, Module mod) {

0 commit comments

Comments
 (0)