Skip to content

Commit fe3c581

Browse files
committed
wip
1 parent fd67e54 commit fe3c581

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

javascript/ql/lib/semmle/javascript/internal/NameResolution.qll

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,17 @@ module NameResolution {
250250
)
251251
}
252252

253+
/**
254+
* A step that treats imports of form `import foo from "somewhere"` as a namespace import,
255+
* to support some non-standard compilers.
256+
*/
257+
private predicate defaultImportInteropStep(Node node1, Node node2) {
258+
exists(ImportDefaultSpecifier spec |
259+
node1 = spec.getImportDeclaration().getImportedPathExpr() and
260+
node2 = spec.getLocal()
261+
)
262+
}
263+
253264
private signature module TypeResolutionInputSig {
254265
/**
255266
* Holds if flow is permitted through the given variable.
@@ -488,7 +499,14 @@ module NameResolution {
488499
/**
489500
* Gets a node to which the given module flows.
490501
*/
491-
predicate trackModule = ValueFlow::TrackNode<ModuleLike>::track/1;
502+
Node trackModule(ModuleLike mod) {
503+
result = mod
504+
or
505+
ValueFlow::step(trackModule(mod), result)
506+
or
507+
defaultImportInteropStep(trackModule(mod), result) and
508+
not mod.(ES2015Module).hasBothNamedAndDefaultExports()
509+
}
492510

493511
predicate trackClassValue = ValueFlow::TrackNode<ClassDefinition>::track/1;
494512

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
testFailures
2+
| pack3/lib.js:1:16:1:33 | | Unexpected result: name=(pack3).libFunction.default |
3+
| pack3/lib.js:1:35:1:118 | // $ na ... unction | Missing result: alias=(pack3).libFunction.default==(pack3).libFunction |
4+
| pack3/lib.js:1:35:1:118 | // $ na ... unction | Missing result: name=(pack3).libFunction |
5+
| pack8/foo.js:1:1:1:12 | | Unexpected result: name=(pack8).Foo.Foo |
6+
| pack8/foo.js:1:14:1:34 | // $ na ... k8).Foo | Missing result: name=(pack8).Foo |
7+
| pack8/foo.js:4:26:4:28 | | Unexpected result: alias=(pack8).Foo.default==(pack8).Foo.Foo |
8+
| pack8/foo.js:4:31:4:73 | // $ al ... k8).Foo | Missing result: alias=(pack8).Foo.default==(pack8).Foo |
9+
| pack8/foo.js:5:27:5:65 | // $ al ... k8).Foo | Missing result: alias=(pack8).Foo.Foo==(pack8).Foo |
10+
| pack10/foo.js:1:34:1:55 | // $ na ... 10).Foo | Missing result: name=(pack10).Foo |
211
ambiguousPreferredPredecessor
312
| pack2/lib.js:1:1:3:1 | def moduleImport("pack2").getMember("exports").getMember("lib").getMember("LibClass").getInstance() |
413
| pack2/lib.js:8:22:8:34 | def moduleImport("pack2").getMember("exports").getMember("lib").getMember("LibClass").getMember("foo") |

0 commit comments

Comments
 (0)