LibraryDependencyMirror API feedback #17742
Labels
area-core-library
SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.
closed-obsolete
Closed as the reported issue is no longer relevant
library-mirrors
type-enhancement
A request for a change that isn't a bug
We are using the LibraryDependencyMirror API to reflect on exported symbols, ensuring that we do not pollute the global namespace.
It works; thank you! Some feedback:
See our use case here: https://github.com/angular/angular.dart/blob/18c11147ad74034c65e959c0d19183ee4c8fd6f0/test/angular_spec.dart
* Suggestion 1: *
Implement a "LibraryViewMirror" which returns a LibraryMirror containing all the symbols visible as the library was imported. e.g.
e.g.
Here, the declarations list would be [Parser];
Instead, I wrote a function that recurses over the library export tree and calculates a list of symbols exported from the library.
The
combinators
mirror proved somewhat difficult to work with. I used them to filter the list of symbols exported from a library.* Suggestion 2: *
I would have preferred a explicit lists:
List<Symbol> get LibraryDependencyMirror.shownSymbols
List<Symbol> get LibraryDependencyMirror.hiddenSymbols
Instead I built that list by iterating over the combinators list. In my case CombinatorMirror.identifiers was always a list of a single element, which was confusing.
* Suggestion 3: *
Rename CombinatorMirror.identifiers to CombinatorMirror.identifier, making it a non-list.
Then I could implement a shownSymbols list using List methods (map, where):
shownSymbols = libDeps.combinators.where((c) => c.isShow).map((c) => c.identifier);
OR
Have LibraryDependencyMirror.combinators be a list of 0 or 1 elements, and have CombinatorMirror.identifiers contain all the hidden or shown symbols.
Them I could implement a shownSymbols list trivially:
shownSymbols = libDeps.combinators.isEmpty || !libDeps.combinators[0].isShow ? [] : libDeps.combinators[0].identifiers;
The text was updated successfully, but these errors were encountered: