add a direct Export step as a PreCallGraphStep

This commit is contained in:
Erik Krogh Kristensen
2020-09-10 00:05:39 +02:00
parent 29457c52dc
commit f2ecb63e5a
6 changed files with 44 additions and 0 deletions

View File

@@ -70,3 +70,8 @@ dataValue
| tst.js:51:30:51:33 | data |
| tst.js:58:16:58:16 | x |
| tst.js:68:16:68:19 | data |
reexport
| reexport/a.js:2:10:2:26 | function foo() {} | reexport/a.js:2:10:2:26 | function foo() {} |
| reexport/a.js:2:10:2:26 | function foo() {} | reexport/test.js:3:13:3:17 | b.foo |
| reexport/b.js:4:10:4:26 | function bar() {} | reexport/b.js:4:10:4:26 | function bar() {} |
| reexport/b.js:4:10:4:26 | function bar() {} | reexport/test.js:4:13:4:17 | b.bar |

View File

@@ -46,3 +46,15 @@ DataFlow::SourceNode dataValue(DataFlow::TypeTracker t) {
}
query DataFlow::SourceNode dataValue() { result = dataValue(DataFlow::TypeTracker::end()) }
DataFlow::SourceNode reexport(DataFlow::TypeTracker t, DataFlow::FunctionNode func) {
t.start() and
func = result and
func.getFile().getParentContainer().getBaseName() = "reexport"
or
exists(DataFlow::TypeTracker t2 | result = reexport(t2, func).track(t2, t))
}
query DataFlow::SourceNode reexport(DataFlow::FunctionNode func) {
result = reexport(DataFlow::TypeTracker::end(), func)
}

View File

@@ -0,0 +1,3 @@
module.exports = {
foo: function foo() {}
}

View File

@@ -0,0 +1,6 @@
const a = require("./a");
module.exports = {
bar: function bar() {}, // name: bar
...a
}

View File

@@ -0,0 +1,4 @@
const b = require("./b");
const foo = b.foo;
const bar = b.bar;