Avoid depending on iterator.current != null. (#877)

With the NNBD change to Dart, it's no longer safe to rely on an iterator returning `null` when it has hit the end (or before calling `moveNext` the first time). For non-nullable element types, it will have to throw instead.

This PR rewrites code that currently rely on a `null` value to recognize the end of an iterator.
This commit is contained in:
Lasse R.H. Nielsen 2020-01-07 22:58:48 +01:00 committed by Natalie Weizenbaum
parent e110961120
commit 31c09606b9

View File

@ -522,14 +522,17 @@ List<List<T>> paths<T>(Iterable<List<T>> choices) => choices.fold(
QueueList<List<ComplexSelectorComponent>> _groupSelectors(
Iterable<ComplexSelectorComponent> complex) {
var groups = QueueList<List<ComplexSelectorComponent>>();
var iterator = complex.iterator..moveNext();
while (iterator.current != null) {
var group = <ComplexSelectorComponent>[];
do {
var iterator = complex.iterator;
if (!iterator.moveNext()) return groups;
var group = <ComplexSelectorComponent>[iterator.current];
groups.add(group);
while (iterator.moveNext()) {
if (group.last is Combinator || iterator.current is Combinator) {
group.add(iterator.current);
} while (iterator.moveNext() &&
(iterator.current is Combinator || group.last is Combinator));
groups.add(group);
} else {
group = [iterator.current];
groups.add(group);
}
}
return groups;
}