Skip to content

Commit ee608be

Browse files
committed
test(symbols): Track the symbols we export from the angular library
Closes dart-archive#398
1 parent 1571459 commit ee608be

File tree

1 file changed

+273
-0
lines changed

1 file changed

+273
-0
lines changed

test/angular_spec.dart

Lines changed: 273 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ library angular_spec;
22

33
import '_specs.dart';
44
import 'package:angular/utils.dart';
5+
import 'dart:mirrors';
56

67
main() {
78
describe('angular.dart unittests', () {
@@ -40,4 +41,276 @@ main() {
4041
}).toThrow('Unknown function type, expecting 0 to 5 args.');
4142
});
4243
});
44+
45+
describe('angular symbols', () {
46+
it('should not export symbols that we do not know about', () {
47+
_getSymbolsFromLibrary(String libraryName) {
48+
var names = [];
49+
var SYMBOL_NAME = new RegExp('"(.*)"');
50+
_unwrapSymbol(sym) => SYMBOL_NAME.firstMatch(sym.toString()).group(1);
51+
52+
var seen = {};
53+
54+
extractSymbols(LibraryMirror lib) {
55+
lib.declarations.forEach((symbol, _) {
56+
names.add([_unwrapSymbol(symbol), _unwrapSymbol(lib.qualifiedName)]);
57+
});
58+
59+
lib.libraryDependencies.forEach((LibraryDependencyMirror libDep) {
60+
LibraryMirror target = libDep.targetLibrary;
61+
if (!libDep.isExport) return;
62+
if (!seen.containsKey(target)) {
63+
seen[target] = true;
64+
extractSymbols(target);
65+
}
66+
});
67+
};
68+
69+
var lib = currentMirrorSystem().findLibrary(new Symbol(libraryName));
70+
71+
extractSymbols(lib);
72+
return names;
73+
}
74+
75+
var names;
76+
try { // Not impleneted in Dart VM 1.2
77+
names = _getSymbolsFromLibrary("angular");
78+
} finally {}
79+
80+
var ALLOWED_PREFIXS = [
81+
"Ng",
82+
"ng",
83+
"Angular",
84+
"_"
85+
];
86+
87+
var ALLOWED_NAMES = [
88+
"di.FactoryFn",
89+
"di.CreationStrategy",
90+
"di.Injector",
91+
"di.TypeFactory",
92+
"di.Visibility",
93+
"di.NoProviderError",
94+
"di.CircularDependencyError",
95+
"di.ObjectFactory",
96+
"di.Module",
97+
"angular.core.AnnotationMap",
98+
"angular.core.LruCache",
99+
"angular.core.ScopeStats",
100+
"angular.core.ArrayFn",
101+
"angular.core.Interpolation",
102+
"angular.core.LongStackTrace",
103+
"angular.core.Cache",
104+
"angular.core.ExpressionVisitor",
105+
"angular.core.ScopeEvent",
106+
"angular.core.MapFn",
107+
"angular.core.EvalFunction1",
108+
"angular.core.MetadataExtractor",
109+
"angular.core.ExceptionHandler",
110+
"angular.core.ZoneOnTurn",
111+
"angular.core.ZoneOnError",
112+
"angular.core.ScopeDigestTTL",
113+
"angular.core.EvalFunction0",
114+
"angular.core.AnnotationsMap",
115+
"angular.core.RootScope",
116+
"angular.core.CacheStats",
117+
"angular.core.ScopeLocals",
118+
"angular.core.ScopeStreamSubscription",
119+
"angular.core.Interpolate",
120+
"angular.core.NOT_IMPLEMENTED",
121+
"angular.core.Scope",
122+
"angular.core.AttrFieldAnnotation",
123+
"angular.core.UnboundedCache",
124+
"angular.core.ScopeStream",
125+
"angular.core.FilterMap",
126+
"angular.core.AstParser",
127+
"angular.watch_group.FunctionApply",
128+
"angular.watch_group.WatchGroup",
129+
"angular.watch_group.ContextReferenceAST",
130+
"angular.watch_group.ConstantAST",
131+
"angular.watch_group.Watch",
132+
"angular.watch_group.ReactionFn",
133+
"angular.watch_group.ChangeLog",
134+
"angular.watch_group.FieldReadAST",
135+
"angular.watch_group.PureFunctionAST",
136+
"angular.watch_group.PrototypeMap",
137+
"angular.watch_group.CollectionAST",
138+
"angular.watch_group.MethodAST",
139+
"angular.watch_group.AST",
140+
"angular.watch_group.RootWatchGroup",
141+
"angular.core.dom.AnimationResult",
142+
"angular.core.dom.WalkingViewFactory",
143+
"angular.core.dom.ResponseError",
144+
"angular.core.dom.View",
145+
"angular.core.dom.ElementBinder",
146+
"angular.core.dom.NoOpAnimation",
147+
"angular.core.dom.AttributeChanged",
148+
"angular.core.dom.HttpBackend",
149+
"angular.core.dom.HttpDefaults",
150+
"angular.core.dom.TaggedElementBinder",
151+
"angular.core.dom.LocationWrapper",
152+
"angular.core.dom.Cookies",
153+
"angular.core.dom.ElementBinderTreeRef",
154+
"angular.core.dom.EventHandler",
155+
"angular.core.dom.Response",
156+
"angular.core.dom.HttpDefaultHeaders",
157+
"angular.core.dom.Animation",
158+
"angular.core.dom.ViewPort",
159+
"angular.core.dom.TemplateLoader",
160+
"angular.core.dom.RequestErrorInterceptor",
161+
"angular.core.dom.TaggedTextBinder",
162+
"angular.core.dom.Http",
163+
"angular.core.dom.BoundViewFactory",
164+
"angular.core.dom.ElementBinderFactory",
165+
"angular.core.dom.DirectiveMap",
166+
"angular.core.dom.BrowserCookies",
167+
"angular.core.dom.HttpInterceptor",
168+
"angular.core.dom.cloneElements",
169+
"angular.core.dom.EventFunction",
170+
"angular.core.dom.RequestInterceptor",
171+
"angular.core.dom.DefaultTransformDataHttpInterceptor",
172+
"angular.core.dom.HttpResponseConfig",
173+
"angular.core.dom.ElementProbe",
174+
"angular.core.dom.ApplyMapping",
175+
"angular.core.dom.ViewCache",
176+
"angular.core.dom.FieldMetadataExtractor",
177+
"angular.core.dom.Compiler",
178+
"angular.core.dom.HttpResponse",
179+
"angular.core.dom.UrlRewriter",
180+
"angular.core.dom.DirectiveRef",
181+
"angular.core.dom.HttpInterceptors",
182+
"angular.core.dom.forceNewDirectivesAndFilters",
183+
"angular.core.dom.DirectiveSelectorFactory",
184+
"angular.core.dom.ObserverChanged",
185+
"angular.core.dom.TaggingViewFactory",
186+
"angular.core.dom.NodeCursor",
187+
"angular.core.dom.TemplateCache",
188+
"angular.core.dom.ViewFactory",
189+
"angular.core.dom.NullTreeSanitizer",
190+
"angular.core.dom.NodeAttrs",
191+
"angular.core.dom.ElementBinderTree",
192+
"angular.core.dom.WalkingCompiler",
193+
"angular.core.dom.TaggingCompiler",
194+
"angular.core.dom.DirectiveSelector",
195+
"angular.core.parser.BoundGetter",
196+
"angular.core.parser.LocalsWrapper",
197+
"angular.core.parser.Getter",
198+
"angular.core.parser.Parser",
199+
"angular.core.parser.ParserBackend",
200+
"angular.core.parser.BoundSetter",
201+
"angular.core.parser.Setter",
202+
"angular.core.parser.syntax.LiteralObject",
203+
"angular.core.parser.syntax.CallMember",
204+
"angular.core.parser.syntax.Filter",
205+
"angular.core.parser.syntax.defaultFilterMap",
206+
"angular.core.parser.syntax.BoundExpression",
207+
"angular.core.parser.syntax.AccessMember",
208+
"angular.core.parser.syntax.Expression",
209+
"angular.core.parser.syntax.AccessScope",
210+
"angular.core.parser.syntax.Assign",
211+
"angular.core.parser.syntax.AccessKeyed",
212+
"angular.core.parser.syntax.CallScope",
213+
"angular.core.parser.syntax.CallFunction",
214+
"angular.core.parser.syntax.Conditional",
215+
"angular.core.parser.syntax.Binary",
216+
"angular.core.parser.syntax.Chain",
217+
"angular.core.parser.syntax.Prefix",
218+
"angular.core.parser.syntax.Literal",
219+
"angular.core.parser.syntax.LiteralString",
220+
"angular.core.parser.syntax.LiteralArray",
221+
"angular.core.parser.syntax.LiteralPrimitive",
222+
"angular.core.parser.syntax.Visitor",
223+
"angular.core.parser.dynamic_parser.DynamicExpression",
224+
"angular.core.parser.dynamic_parser.ClosureMap",
225+
"angular.core.parser.dynamic_parser.DynamicParser",
226+
"angular.core.parser.dynamic_parser.DynamicParserBackend",
227+
"angular.core.parser.static_parser.StaticParserFunctions",
228+
"angular.core.parser.static_parser.StaticExpression",
229+
"angular.core.parser.static_parser.StaticParser",
230+
"angular.core.parser.lexer.Scanner",
231+
"angular.core.parser.lexer.OPERATORS",
232+
"angular.core.parser.lexer.NumberToken",
233+
"angular.core.parser.lexer.Token",
234+
"angular.core.parser.lexer.IdentifierToken",
235+
"angular.core.parser.lexer.StringToken",
236+
"angular.core.parser.lexer.CharacterToken",
237+
"angular.core.parser.lexer.Lexer",
238+
"angular.core.parser.lexer.KEYWORDS",
239+
"angular.core.parser.lexer.OperatorToken",
240+
"angular.directive.ItemEval",
241+
"angular.directive.OptionValueDirective",
242+
"angular.directive.InputSelectDirective",
243+
"angular.directive.InputTextLikeDirective",
244+
"angular.directive.InputNumberLikeDirective",
245+
"angular.directive.ContentEditableDirective",
246+
"angular.directive.InputCheckboxDirective",
247+
"angular.directive.InputRadioDirective",
248+
"angular.filter.JsonFilter",
249+
"angular.filter.Equals",
250+
"angular.filter.Mapper",
251+
"angular.filter.FilterFilter",
252+
"angular.filter.NumberFilter",
253+
"angular.filter.DateFilter",
254+
"angular.filter.LowercaseFilter",
255+
"angular.filter.UppercaseFilter",
256+
"angular.filter.OrderByFilter",
257+
"angular.filter.CurrencyFilter",
258+
"angular.filter.LimitToFilter",
259+
"angular.filter.Predicate",
260+
"angular.routing.RouteInitializerFn",
261+
"angular.routing.RouteProvider",
262+
"angular.routing.RouteInitializer",
263+
"angular.routing.RouteViewFactory",
264+
"route.client.RouteHandle",
265+
"route.client.RouteEnterEvent",
266+
"route.client.RouteStartEvent",
267+
"route.client.Router",
268+
"route.client.RouteEvent",
269+
"route.client.childRoute",
270+
"route.client.RouteLeaveEventHandler",
271+
"route.client.Route",
272+
"route.client.RouteLeaveEvent",
273+
"route.client.RoutePreEnterEventHandler",
274+
"route.client.RoutePreEnterEvent",
275+
"route.client.Routable",
276+
"route.client.RouteEnterEventHandler",
277+
"url_matcher.UrlMatcher",
278+
"url_matcher.UrlMatch",
279+
"dirty_checking_change_detector.FieldGetter",
280+
"dirty_checking_change_detector.DirtyCheckingChangeDetector",
281+
"dirty_checking_change_detector.DirtyCheckingRecord",
282+
"dirty_checking_change_detector.ItemRecord",
283+
"dirty_checking_change_detector.KeyValueRecord",
284+
"dirty_checking_change_detector.DuplicateMap",
285+
"dirty_checking_change_detector.GetterCache",
286+
"dirty_checking_change_detector.DirtyCheckingChangeDetectorGroup"
287+
];
288+
289+
var _nameMap = {};
290+
ALLOWED_NAMES.forEach((x) => _nameMap[x] = true);
291+
292+
assertSymbolNameIsOk(List nameInfo) {
293+
String name = nameInfo[0];
294+
String libName = nameInfo[1];
295+
296+
if (ALLOWED_PREFIXS.any((prefix) =>
297+
name.startsWith(prefix))) return;
298+
299+
var key = "$libName.$name";
300+
if (_nameMap.containsKey(key)) {
301+
_nameMap[key] = false;
302+
return;
303+
}
304+
305+
throw "Symbol $key is exported thru the angular library, but it shouldn't be";
306+
};
307+
308+
names.forEach(assertSymbolNameIsOk);
309+
310+
// If there are keys that no longer need to be in the ALLOWED_NAMES list, complain.
311+
_nameMap.forEach((k,v) {
312+
if (v) print("angular_spec.dart: Unused ALLOWED_NAMES key $k");
313+
});
314+
});
315+
});
43316
}

0 commit comments

Comments
 (0)