Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 28efade

Browse files
committed
JS: Use defSourceNode from getRhsNode
1 parent 747c320 commit 28efade

4 files changed

Lines changed: 17 additions & 15 deletions

File tree

javascript/ql/src/semmle/javascript/SSA.qll

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -527,20 +527,7 @@ class SsaExplicitDefinition extends SsaDefinition, TExplicitDef {
527527
* if any.
528528
*/
529529
DataFlow::Node getRhsNode() {
530-
exists(VarDef def | def = getDef() |
531-
result = def.getSource().flow()
532-
or
533-
exists(VarRef ref |
534-
ref = getSourceVariable().getAReference() and
535-
def.getTarget().(BindingPattern).getABindingVarRef() = ref and
536-
result = DataFlow::patternPropRead(ref)
537-
)
538-
or
539-
result = DataFlow::parameterNode(def)
540-
or
541-
// Handle class, function, namespace, and enum declaration statement
542-
result.getAstNode() = def.(Stmt)
543-
)
530+
result = DataFlow::defSourceNode(getDef(), getSourceVariable())
544531
}
545532
}
546533

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1318,10 +1318,12 @@ module DataFlow {
13181318
}
13191319

13201320
/**
1321+
* INTERNAL. DO NOT USE.
1322+
*
13211323
* Gets the data flow node representing the source of the definition of `v` at `def`,
13221324
* if any.
13231325
*/
1324-
private Node defSourceNode(VarDef def, SsaSourceVariable v) {
1326+
Node defSourceNode(VarDef def, SsaSourceVariable v) {
13251327
exists(BindingPattern lhs, VarRef r |
13261328
lhs = def.getTarget() and r = lhs.getABindingVarRef() and r.getVariable() = v
13271329
|

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ test_fromReference
5050
| test.js:24:9:24:10 | NS | NS |
5151
| test.js:24:9:24:16 | NS \|\| {} | NS |
5252
| test.js:26:1:26:8 | Conflict | Conflict |
53+
| test.js:33:7:33:18 | { bar = {} } | foo |
54+
| test.js:33:7:33:24 | bar | foo.bar |
55+
| test.js:33:9:33:16 | bar = {} | foo.bar |
56+
| test.js:33:22:33:24 | foo | foo |
57+
| test.js:34:11:34:13 | bar | foo.bar |
58+
| test.js:34:11:34:17 | bar.baz | foo.bar.baz |
5359
test_fromRhs
5460
| other_ns.js:4:9:4:16 | NS \|\| {} | NS |
5561
| other_ns.js:6:12:6:13 | {} | Conflict |
@@ -58,7 +64,9 @@ test_fromRhs
5864
| test.js:26:12:26:13 | {} | Conflict |
5965
| test.js:28:1:28:20 | class GlobalClass {} | GlobalClass |
6066
| test.js:30:1:30:28 | functio ... on() {} | globalFunction |
67+
| test.js:32:1:35:1 | functio ... .baz'\\n} | destruct |
6168
test_assignedUnique
6269
| GlobalClass |
70+
| destruct |
6371
| f |
6472
| globalFunction |

javascript/ql/test/library-tests/GlobalAccessPaths/test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,8 @@ Conflict = {}; // assigned in multiple files
2828
class GlobalClass {}
2929

3030
function globalFunction() {}
31+
32+
function destruct() {
33+
let { bar = {} } = foo;
34+
let v = bar.baz; // 'foo.bar.baz'
35+
}

0 commit comments

Comments
 (0)