@@ -72,8 +72,19 @@ class ChainBuilder {
72
72
if (_root case CascadeExpression cascade) {
73
73
_visitTarget (cascade.target);
74
74
75
+ // When [_root] is a cascade, the chain is the series of cascade sections.
75
76
for (var section in cascade.cascadeSections) {
76
- _unwrapCall (section);
77
+ var piece = _visitor.nodePiece (section);
78
+
79
+ var callType = switch (section) {
80
+ MethodInvocation (argumentList: var args)
81
+ when args.arguments.canSplit (args.rightParenthesis) =>
82
+ CallType .splittableCall,
83
+ MethodInvocation () => CallType .unsplittableCall,
84
+ _ => CallType .property,
85
+ };
86
+
87
+ _calls.add (ChainCall (piece, callType));
77
88
}
78
89
} else {
79
90
_unwrapCall (_root);
@@ -160,9 +171,6 @@ class ChainBuilder {
160
171
/// Given [expression] , which is the expression for some call chain, traverses
161
172
/// the selectors to fill in the list of [_calls] .
162
173
///
163
- /// If [_root] is a [CascadeSection] , then this is called once for each
164
- /// section in the cascade.
165
- ///
166
174
/// Otherwise, it's a method chain, and this recursively calls itself for the
167
175
/// targets to unzip and flatten the nested selector expressions. Then it
168
176
/// initializes [_target] with the innermost subexpression that isn't a part
@@ -176,10 +184,8 @@ class ChainBuilder {
176
184
/// .baz[0][1]
177
185
/// .bang()
178
186
void _unwrapCall (Expression expression) {
179
- var isCascade = _root is CascadeExpression ;
180
-
181
187
switch (expression) {
182
- case Expression (looksLikeStaticCall: true ) when ! isCascade :
188
+ case Expression (looksLikeStaticCall: true ):
183
189
// Don't include things that look like static method or constructor
184
190
// calls in the call chain because that tends to split up named
185
191
// constructors from their class.
@@ -191,8 +197,8 @@ class ChainBuilder {
191
197
expression.operator , expression.rightHandSide);
192
198
_calls.add (ChainCall (piece, CallType .property));
193
199
194
- case MethodInvocation (: var target) when isCascade || target != null :
195
- if (target != null ) _unwrapCall (target);
200
+ case MethodInvocation (: var target? ) :
201
+ _unwrapCall (target);
196
202
197
203
var callPiece = _visitor.buildPiece ((b) {
198
204
b.token (expression.operator );
@@ -206,8 +212,8 @@ class ChainBuilder {
206
212
_calls.add (ChainCall (callPiece,
207
213
canSplit ? CallType .splittableCall : CallType .unsplittableCall));
208
214
209
- case PropertyAccess (: var target):
210
- if (target != null ) _unwrapCall (target);
215
+ case PropertyAccess (: var target? ):
216
+ _unwrapCall (target);
211
217
212
218
var piece = _visitor.buildPiece ((b) {
213
219
b.token (expression.operator );
@@ -217,7 +223,7 @@ class ChainBuilder {
217
223
_calls.add (ChainCall (piece, CallType .property));
218
224
219
225
case PrefixedIdentifier (: var prefix):
220
- if ( ! isCascade) _unwrapCall (prefix);
226
+ _unwrapCall (prefix);
221
227
222
228
var piece = _visitor.buildPiece ((b) {
223
229
b.token (expression.period);
@@ -236,19 +242,6 @@ class ChainBuilder {
236
242
});
237
243
});
238
244
239
- case IndexExpression () when isCascade && _calls.isEmpty:
240
- // An index expression as the first cascade section should be part of
241
- // the cascade chain and not part of the target, as in:
242
- //
243
- // foo
244
- // ..[index]
245
- // ..another();
246
- //
247
- // For non-cascade method chains, we keep leave the index as part of
248
- // the target since the method chain doesn't begin until the first `.`.
249
- var piece = _visitor.createIndexExpression (null , expression);
250
- _calls.add (ChainCall (piece, CallType .property));
251
-
252
245
case IndexExpression ():
253
246
_unwrapPostfix (expression.target! , (target) {
254
247
return _visitor.createIndexExpression (target, expression);
@@ -264,7 +257,7 @@ class ChainBuilder {
264
257
265
258
default :
266
259
// Otherwise, it isn't a selector so we've reached the target.
267
- if ( ! isCascade) _visitTarget (expression);
260
+ _visitTarget (expression);
268
261
}
269
262
}
270
263
0 commit comments