Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* Added support for data flow through property patterns in `is` expressions and `switch` cases.
Original file line number Diff line number Diff line change
Expand Up @@ -2308,6 +2308,31 @@ private predicate readStepDelegateCall(Node node1, ContentSet c, OutNode node2)
)
}

/**
* Holds if data can flow from `node1` to `node2` via a property pattern.
*/
private predicate fieldOrPropertyPatternRead(Node node1, ContentSet c, Node node2) {
exists(PatternExpr pattern, LabeledPatternExpr label, FieldOrProperty f |
node1.asExpr() = pattern and
(
pattern.(RecursivePatternExpr).getPropertyPatterns().getPattern(_) = label
or
pattern.(PropertyPatternExpr).getPattern(_) = label
) and
c = f.getContentSet() and
f.getName() = label.getLabel()
|
node2.asExpr() = label.(RecursivePatternExpr)
or
node2.asExpr() = label.(PropertyPatternExpr)
or
exists(AssignableDefinitions::PatternDefinition lvd |
node2.(AssignableDefinitionNode).getDefinition() = lvd and
label.(BindingPatternExpr).getVariableDeclExpr() = lvd.getDeclaration()
)
)
}

/**
* Holds if data can flow from `node1` to `node2` via a read of content `c`.
*/
Expand All @@ -2319,6 +2344,8 @@ predicate readStep(Node node1, ContentSet c, Node node2) {
or
fieldOrPropertyRead(node1.asExpr(), c, node2.asExpr())
or
fieldOrPropertyPatternRead(node1, c, node2)
or
dynamicPropertyRead(node1.asExpr(), c, node2.asExpr())
or
node2.asExpr().(AwaitExpr).getExpr() = node1.asExpr() and
Expand Down
Loading
Loading