visitCascadeExpression method
Visit a SCascadeExpression.
Implementation
@override
Object? visitCascadeExpression(SCascadeExpression node) {
// 1. Evaluate the target expression ONCE.
final targetValue = node.target!.accept<Object?>(this);
// 2. Execute each cascade section ON THE ORIGINAL targetValue.
for (final section in node.cascadeSections) {
// We need to manually handle each section type, forcing the target.
if (section is SMethodInvocation) {
_executeCascadeMethodInvocation(targetValue, section);
} else if (section is SPropertyAccess) {
// Evaluate property access for potential side effects (getters), but discard result.
_executeCascadePropertyAccess(targetValue, section);
} else if (section is SAssignmentExpression) {
_executeCascadeAssignment(targetValue, section);
} else if (section is SIndexExpression) {
// Evaluate index expression for potential side effects (getters?), but discard result.
_executeCascadeIndexAccess(targetValue, section);
} else {
// Should not happen with valid cascade sections
throw UnimplementedD4rtException(
'Cascade section type not handled: ${section.runtimeType}',
);
}
}
// 3. The cascade expression evaluates to the original target value.
return targetValue;
}