Skip to content

Commit e86fe85

Browse files
scheglovCommit Queue
authored and
Commit Queue
committed
Suppport ForEachPartsWithPattern in NodeReplacer.
Change-Id: I152f3c7b0500db9ad4ca633dd0f4491cea460f53 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/281465 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 22882c4 commit e86fe85

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

pkg/analyzer/lib/src/dart/ast/utilities.dart

+10
Original file line numberDiff line numberDiff line change
@@ -2513,6 +2513,16 @@ class NodeReplacer extends ThrowingAstVisitor<bool> {
25132513
return visitNode(node);
25142514
}
25152515

2516+
@override
2517+
bool? visitForEachPartsWithPattern(ForEachPartsWithPattern node) {
2518+
if (identical(node.iterable, _oldNode)) {
2519+
(node as ForEachPartsWithPatternImpl).iterable =
2520+
_newNode as ExpressionImpl;
2521+
return true;
2522+
}
2523+
return visitNode(node);
2524+
}
2525+
25162526
@override
25172527
bool visitForElement(ForElement node) {
25182528
if (identical(node.forLoopParts, _oldNode)) {

pkg/analyzer/test/generated/utilities_test.dart

+16
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,22 @@ void f() {
876876
);
877877
}
878878

879+
void test_forEachPartsWithPattern() {
880+
var findNode = _parseStringToFindNode(r'''
881+
void f() {
882+
for (var (a) in []) {}
883+
for (var (b) in []) {}
884+
}
885+
''');
886+
_assertReplacementForChildren<ForEachPartsWithPattern>(
887+
destination: findNode.forEachPartsWithPattern('(a)'),
888+
source: findNode.forEachPartsWithPattern('(b)'),
889+
childAccessors: [
890+
(node) => node.iterable,
891+
],
892+
);
893+
}
894+
879895
void test_forEachStatement_withIdentifier() {
880896
var findNode = _parseStringToFindNode(r'''
881897
void f(int a) {

0 commit comments

Comments
 (0)