Skip to content

Commit e62313b

Browse files
authored
Simplify ChainPiece. (#1595)
We were still passing in allowNewlines to _formatCall() even though that parameter was no longer used once Piece got the allowChildInState() API. So I removed that. Then I noticed that the switch in _formatCall() could be more cleanly handled by having the cases in format() calculate separate directly. So I did that. That left _formatCall() not actually doing anything useful, so I got rid of it. There are no behavioral change, it's just a code clean-up.
1 parent 4e6f44d commit e62313b

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

lib/src/piece/chain.dart

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ final class ChainPiece extends Piece {
168168
writer.format(_target);
169169

170170
for (var i = 0; i < _calls.length; i++) {
171-
_formatCall(writer, state, i, allowNewlines: false);
171+
writer.format(_calls[i]._call);
172172
}
173173

174174
case _splitAfterProperties:
@@ -177,7 +177,10 @@ final class ChainPiece extends Piece {
177177

178178
for (var i = 0; i < _calls.length; i++) {
179179
writer.splitIf(i >= _leadingProperties, space: false);
180-
_formatCall(writer, state, i, allowNewlines: i >= _leadingProperties);
180+
181+
// Every non-property call except the last will be on its own line.
182+
writer.format(_calls[i]._call,
183+
separate: i >= _leadingProperties && i < _calls.length - 1);
181184
}
182185

183186
writer.popIndent();
@@ -186,7 +189,7 @@ final class ChainPiece extends Piece {
186189
writer.format(_target);
187190

188191
for (var i = 0; i < _calls.length; i++) {
189-
_formatCall(writer, state, i, allowNewlines: i == _blockCallIndex);
192+
writer.format(_calls[i]._call);
190193
}
191194

192195
case State.split:
@@ -195,27 +198,16 @@ final class ChainPiece extends Piece {
195198

196199
for (var i = 0; i < _calls.length; i++) {
197200
writer.newline();
198-
_formatCall(writer, state, i);
201+
202+
// The chain is fully split so every call except for the last is on
203+
// its own line.
204+
writer.format(_calls[i]._call, separate: i < _calls.length - 1);
199205
}
200206

201207
writer.popIndent();
202208
}
203209
}
204210

205-
void _formatCall(CodeWriter writer, State state, int i,
206-
{bool allowNewlines = true}) {
207-
// If the chain is fully split, then every call except for the last will
208-
// be on its own line. If the chain is split after properties, then
209-
// every non-property call except the last will be on its own line.
210-
var separate = switch (state) {
211-
_splitAfterProperties => i >= _leadingProperties && i < _calls.length - 1,
212-
State.split => i < _calls.length - 1,
213-
_ => false,
214-
};
215-
216-
writer.format(_calls[i]._call, separate: separate);
217-
}
218-
219211
@override
220212
void forEachChild(void Function(Piece piece) callback) {
221213
callback(_target);

0 commit comments

Comments
 (0)