Skip to content

Commit afcdc12

Browse files
committed
JS: Use ValueNode, not SSA node, to model NamedImportSpecifier
1 parent 9eebe00 commit afcdc12

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

javascript/ql/src/semmle/javascript/DefUse.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ private predicate defn(ControlFlowNode def, Expr lhs, AST::ValueNode rhs) {
4040
or
4141
exists(ImportEqualsDeclaration i | def = i | lhs = i.getId() and rhs = i.getImportedEntity())
4242
or
43+
exists(ImportSpecifier i | def = i | lhs = i.getLocal() and rhs = i)
44+
or
4345
exists(EnumMember member | def = member.getIdentifier() |
4446
lhs = def and rhs = member.getInitializer()
4547
)
@@ -71,8 +73,6 @@ private predicate defn(ControlFlowNode def, Expr lhs) {
7173
or
7274
lhs = def.(UpdateExpr).getOperand().getUnderlyingReference()
7375
or
74-
lhs = def.(ImportSpecifier).getLocal()
75-
or
7676
exists(EnhancedForLoop efl | def = efl.getIteratorExpr() |
7777
lhs = def.(Expr).stripParens() or
7878
lhs = def.(VariableDeclarator).getBindingPattern()

javascript/ql/src/semmle/javascript/dataflow/DataFlow.qll

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -799,21 +799,21 @@ module DataFlow {
799799
/**
800800
* A named import specifier seen as a property read on the imported module.
801801
*/
802-
private class ImportSpecifierAsPropRead extends PropRead {
802+
private class ImportSpecifierAsPropRead extends PropRead, ValueNode {
803+
override ImportSpecifier astNode;
804+
803805
ImportDeclaration imprt;
804-
ImportSpecifier spec;
805806

806807
ImportSpecifierAsPropRead() {
807-
spec = imprt.getASpecifier() and
808-
exists(spec.getImportedName()) and
809-
this = ssaDefinitionNode(SSA::definition(spec))
808+
astNode = imprt.getASpecifier() and
809+
exists(astNode.getImportedName())
810810
}
811811

812812
override Node getBase() { result = TDestructuredModuleImportNode(imprt) }
813813

814-
override Expr getPropertyNameExpr() { result = spec.getImported() }
814+
override Expr getPropertyNameExpr() { result = astNode.getImported() }
815815

816-
override string getPropertyName() { result = spec.getImportedName() }
816+
override string getPropertyName() { result = astNode.getImportedName() }
817817
}
818818

819819
/**

javascript/ql/src/semmle/javascript/dataflow/Sources.qll

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,13 @@ module SourceNode {
234234
astNode instanceof AwaitExpr or
235235
astNode instanceof FunctionSentExpr or
236236
astNode instanceof FunctionBindExpr or
237-
astNode instanceof DynamicImportExpr
237+
astNode instanceof DynamicImportExpr or
238+
astNode instanceof NamedImportSpecifier
238239
)
239240
or
240-
this = DataFlow::ssaDefinitionNode(SSA::definition(any(ImportSpecifier imp)))
241+
this = DataFlow::ssaDefinitionNode(SSA::definition(any(ImportNamespaceSpecifier imp)))
242+
or
243+
this = DataFlow::ssaDefinitionNode(SSA::definition(any(ImportDefaultSpecifier imp)))
241244
or
242245
DataFlow::parameterNode(this, _)
243246
or

javascript/ql/test/library-tests/DataFlow/flowStep.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
| sources.js:5:4:5:5 | 23 | sources.js:3:11:3:11 | x |
1010
| tst.js:1:1:1:1 | x | tst.js:28:2:28:1 | x |
1111
| tst.js:1:1:1:1 | x | tst.js:32:1:32:0 | x |
12+
| tst.js:1:10:1:11 | fs | tst.js:1:10:1:11 | fs |
1213
| tst.js:1:10:1:11 | fs | tst.js:7:1:7:2 | fs |
1314
| tst.js:1:10:1:11 | fs | tst.js:22:24:22:25 | fs |
1415
| tst.js:3:5:3:10 | x | tst.js:8:1:8:1 | x |

0 commit comments

Comments
 (0)