Description
I don't get any errors in:
import 'foo.dart' as foo if (dart.library.html) 'other_foo.dart';
main() {
print(foo.bar);
}
This runs if I run it with dart temp.dart
and analyzes without error using dart analyze
. The grammar for imports is:
⟨importSpecification⟩ ::=
import ⟨configurableUri⟩ (deferred? as ⟨typeIdentifier⟩)? ⟨combinator⟩*
‘;’
That means that the as
clause, if present, must be after any if
configurations.
I ran into this issue because dart format
will always output the as
clause after the if
configurations, which then trips up its sanity check because it made a non-whitespace change by reordering those clauses.
I did find at least two libraries in the wild (dotlottie_loader-0.0.4/lib/src/loaders/network_loader.dart and sentry-8.3.0/lib/src/environment/environment_variables.dart) that has the clauses in the wrong order, so fixing this is both nominally and actually a breaking change (though likely a very minor one given the rarity of conditional imports).