Skip to content

Commit

Permalink
Suppport ForEachPartsWithPattern in NodeReplacer.
Browse files Browse the repository at this point in the history
Change-Id: I152f3c7b0500db9ad4ca633dd0f4491cea460f53
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/281465
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
  • Loading branch information
scheglov authored and Commit Queue committed Feb 7, 2023
1 parent 22882c4 commit e86fe85
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/analyzer/lib/src/dart/ast/utilities.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2513,6 +2513,16 @@ class NodeReplacer extends ThrowingAstVisitor<bool> {
return visitNode(node);
}

@override
bool? visitForEachPartsWithPattern(ForEachPartsWithPattern node) {
if (identical(node.iterable, _oldNode)) {
(node as ForEachPartsWithPatternImpl).iterable =
_newNode as ExpressionImpl;
return true;
}
return visitNode(node);
}

@override
bool visitForElement(ForElement node) {
if (identical(node.forLoopParts, _oldNode)) {
Expand Down
16 changes: 16 additions & 0 deletions pkg/analyzer/test/generated/utilities_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,22 @@ void f() {
);
}

void test_forEachPartsWithPattern() {
var findNode = _parseStringToFindNode(r'''
void f() {
for (var (a) in []) {}
for (var (b) in []) {}
}
''');
_assertReplacementForChildren<ForEachPartsWithPattern>(
destination: findNode.forEachPartsWithPattern('(a)'),
source: findNode.forEachPartsWithPattern('(b)'),
childAccessors: [
(node) => node.iterable,
],
);
}

void test_forEachStatement_withIdentifier() {
var findNode = _parseStringToFindNode(r'''
void f(int a) {
Expand Down

0 comments on commit e86fe85

Please sign in to comment.