Skip to content

Commit 5da04ea

Browse files
authored
Format collection spread elements. (#1341)
Unlike the old tests, I didn't redundantly test everything you can do with spreads in all three kinds of collection literals. Since we know those literals all use the same implementation, that seemed needlessly redundant to me.
1 parent b79b628 commit 5da04ea

File tree

3 files changed

+69
-3
lines changed

3 files changed

+69
-3
lines changed

lib/src/front_end/ast_node_visitor.dart

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,15 @@ class AstNodeVisitor extends ThrowingAstVisitor<Piece> with PieceFactory {
861861

862862
@override
863863
Piece visitFunctionExpressionInvocation(FunctionExpressionInvocation node) {
864-
throw UnimplementedError();
864+
// TODO(tall): This is just basic support to get the syntax doing something
865+
// so that tests of other features that happen to use this syntax can run.
866+
// The main tests for function expression calls still need to be migrated
867+
// over and this may need some tweaks.
868+
return buildPiece((b) {
869+
b.visit(node.function);
870+
b.visit(node.typeArguments);
871+
b.visit(node.argumentList);
872+
});
865873
}
866874

867875
@override
@@ -1408,7 +1416,10 @@ class AstNodeVisitor extends ThrowingAstVisitor<Piece> with PieceFactory {
14081416

14091417
@override
14101418
Piece visitSpreadElement(SpreadElement node) {
1411-
throw UnimplementedError();
1419+
return buildPiece((b) {
1420+
b.token(node.spreadOperator);
1421+
b.visit(node.expression);
1422+
});
14121423
}
14131424

14141425
@override

test/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ declaration/ - Typedef, class, enum, extension, mixin, and member declarations.
6767
Includes constructors, getters, setters, methods, and fields,
6868
but not functions and variables, which are in their own
6969
directories below.
70-
expression/ - Expressions.
70+
expression/ - Expressions and collection elements.
7171
invocation/ - Function and member invocations.
7272
selection/ - Test preserving selection information.
7373
statement/ - Statements.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
40 columns |
2+
>>> Unsplit.
3+
var list = [ ... a,...b, ...
4+
c];
5+
<<<
6+
var list = [...a, ...b, ...c];
7+
>>> Don't split after `...`.
8+
var list = [...comicallyLongIdentifierThatOverflows];
9+
<<<
10+
var list = [
11+
...comicallyLongIdentifierThatOverflows,
12+
];
13+
>>> Null-aware.
14+
var list = [ ...? a,...?b, ...?
15+
c];
16+
<<<
17+
var list = [...?a, ...?b, ...?c];
18+
>>> Don't split after `...?`.
19+
var list = [...?comicallyLongIdentifierThatOverflows];
20+
<<<
21+
var list = [
22+
...?comicallyLongIdentifierThatOverflows,
23+
];
24+
>>> Split inside spread expression.
25+
var list = [1, ...some + very + long + spread + expression, 3];
26+
<<<
27+
var list = [
28+
1,
29+
...some +
30+
very +
31+
long +
32+
spread +
33+
expression,
34+
3,
35+
];
36+
>>> Spread function expression.
37+
var list = [1, ...() { body; }, 4];
38+
<<<
39+
var list = [
40+
1,
41+
...() {
42+
body;
43+
},
44+
4,
45+
];
46+
>>> Spread immediately invoked function expression.
47+
var list = [1, ...() sync* { yield thing; }(), 4];
48+
<<<
49+
var list = [
50+
1,
51+
...() sync* {
52+
yield thing;
53+
}(),
54+
4,
55+
];

0 commit comments

Comments
 (0)