Is it allowed to have several externalLibrary ?
a14n opened this issue · comments
In Linking to external libraries:
A canonical library can wire itself up with zero or more external libraries using an external library directive
I understand more as >=1
but in the definition of libraryDefinition
I see:
libraryDefinition:
scriptTag? libraryName? (externalLibrary|externalForLibrary)? importOrExport* partDirective* topLevelDefinition*
;
If I understand correctly that means 0 or 1 externalLibrary
.
So is it allowed to have several external libraries ?
In the context of source gen it's likely that several external lib could be used (Eg. one for JSON, one for identity(hashcode
/ .==
), one for toString()
) Moreover those external libraries would define only some of all the external members of a class from the canonical lib.
Here is an example:
person.dart
external library 'person-json.g.dart';
external library 'person-identity.g.dart';
external library 'person-tostring.g.dart';
class Person {
final String name;
Person(this.name);
external Person.fromJson(Map json);
external Map toJson();
external int get hashCode;
external bool operator ==(o);
external String toString();
}
person-json.g.dart
external library for 'person.dart';
import 'dart:convert';
class Person {
factory Person.fromJson(Map json) => new Person(json["name"]);
Map toJson() => {"name": name};
}
person-identity.g.dart
external library for 'person.dart';
import 'dart:convert';
class Person {
int get hashCode => hashObjects([name]);
bool operator ==(o) => identical(this, o) || o.runtimeType == runtimeType && o.name == name;
}
person-tostring.g.dart
external library for 'person.dart';
import 'dart:convert';
class Person {
String toString() => "Person(name=$name)";
}
Is it a valid usage of external libraries (particularly partial patches) ?