Skip to content

Commit 633b01c

Browse files
authored
Format super expressions. (#1366)
Apparently the old formatter has *zero* tests of this. I went ahead and wrote tests of all of the ways `super` appears in the grammar. That's probably overkill given that the analyzer models `super` as a standalone expression, but that's not actually how it works in the language itself. (In Dart, `print(super)` isn't syntactically valid.) I figured it made sense to write tests closer to the grammar.
1 parent e697b6e commit 633b01c

File tree

2 files changed

+112
-1
lines changed

2 files changed

+112
-1
lines changed

lib/src/front_end/ast_node_visitor.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1591,7 +1591,7 @@ class AstNodeVisitor extends ThrowingAstVisitor<Piece> with PieceFactory {
15911591

15921592
@override
15931593
Piece visitSuperExpression(SuperExpression node) {
1594-
throw UnimplementedError();
1594+
return tokenPiece(node.superKeyword);
15951595
}
15961596

15971597
@override

test/invocation/super.stmt

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
40 columns |
2+
>>> Unnamed call.
3+
super ( arg1 , arg2 );
4+
<<<
5+
super(arg1, arg2);
6+
>>> Unnamed call with type arguments.
7+
super < int , double > ( arg1 , arg2 );
8+
<<<
9+
super<int, double>(arg1, arg2);
10+
>>> Named call.
11+
super . name ( arg1 , arg2 );
12+
<<<
13+
super.name(arg1, arg2);
14+
>>> Named call with type arguments.
15+
super . name < int , double > ( arg1 , arg2 );
16+
<<<
17+
super.name<int, double>(arg1, arg2);
18+
>>> Getter.
19+
super . name;
20+
<<<
21+
super.name;
22+
>>> Setter.
23+
super . name = value;
24+
<<<
25+
super.name = value;
26+
>>> Equality operators.
27+
{
28+
super == other;
29+
super != other;
30+
}
31+
<<<
32+
{
33+
super == other;
34+
super != other;
35+
}
36+
>>> Comparison operators.
37+
{
38+
super < other;
39+
super <= other;
40+
super > other;
41+
super >= other;
42+
}
43+
<<<
44+
{
45+
super < other;
46+
super <= other;
47+
super > other;
48+
super >= other;
49+
}
50+
>>> Bitwise operators.
51+
{
52+
super & other;
53+
super ^ other;
54+
super | other;
55+
}
56+
<<<
57+
{
58+
super & other;
59+
super ^ other;
60+
super | other;
61+
}
62+
>>> Shift operators.
63+
{
64+
super << other;
65+
super >> other;
66+
super >>> other;
67+
}
68+
<<<
69+
{
70+
super << other;
71+
super >> other;
72+
super >>> other;
73+
}
74+
>>> Additive operators.
75+
{
76+
super + other;
77+
super - other;
78+
}
79+
<<<
80+
{
81+
super + other;
82+
super - other;
83+
}
84+
>>> Multiplicative operators.
85+
{
86+
super * other;
87+
super / other;
88+
super % other;
89+
super ~/ other;
90+
}
91+
<<<
92+
{
93+
super * other;
94+
super / other;
95+
super % other;
96+
super ~/ other;
97+
}
98+
>>> Unary operators.
99+
{
100+
- super;
101+
~ super;
102+
}
103+
<<<
104+
{
105+
-super;
106+
~super;
107+
}
108+
>>> Don't remove all spaces between multiple unary minuses.
109+
- - - super;
110+
<<<
111+
- - -super;

0 commit comments

Comments
 (0)