Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Side by Side Diff: pkg/polymer/lib/src/build/script_compactor.dart

Issue 700733002: Track initializers already seen (fixes #21439) (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/polymer/pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /// Transfomer that combines multiple dart script tags into a single one. 5 /// Transfomer that combines multiple dart script tags into a single one.
6 library polymer.src.build.script_compactor; 6 library polymer.src.build.script_compactor;
7 7
8 import 'dart:async'; 8 import 'dart:async';
9 import 'dart:convert'; 9 import 'dart:convert';
10 10
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 new _HtmlExtractor(logger, generator, publishedAttributes, 242 new _HtmlExtractor(logger, generator, publishedAttributes,
243 expressionVisitor).visit(document); 243 expressionVisitor).visit(document);
244 244
245 // Create a recorder that uses analyzer data to feed data to [generator]. 245 // Create a recorder that uses analyzer data to feed data to [generator].
246 var recorder = new Recorder(generator, 246 var recorder = new Recorder(generator,
247 (lib) => resolver.getImportUri(lib, from: bootstrapId).toString()); 247 (lib) => resolver.getImportUri(lib, from: bootstrapId).toString());
248 248
249 // Process all classes and top-level functions to include initializers, 249 // Process all classes and top-level functions to include initializers,
250 // register custom elements, and include special fields and methods in 250 // register custom elements, and include special fields and methods in
251 // custom element classes. 251 // custom element classes.
252 var functionsSeen = new Set<FunctionElement>();
253 var classesSeen = new Set<ClassElement>();
252 for (var id in entryLibraries) { 254 for (var id in entryLibraries) {
253 var lib = resolver.getLibrary(id); 255 var lib = resolver.getLibrary(id);
254 for (var fun in _visibleTopLevelMethodsOf(lib)) { 256 for (var fun in _visibleTopLevelMethodsOf(lib)) {
257 if (functionsSeen.contains(fun)) continue;
258 functionsSeen.add(fun);
255 _processFunction(fun, id); 259 _processFunction(fun, id);
256 } 260 }
257 261
258 for (var cls in _visibleClassesOf(lib)) { 262 for (var cls in _visibleClassesOf(lib)) {
263 if (classesSeen.contains(cls)) continue;
264 classesSeen.add(cls);
259 _processClass(cls, id, recorder); 265 _processClass(cls, id, recorder);
260 } 266 }
261 } 267 }
262 } 268 }
263 269
264 /// Process a class ([cls]). If it contains an appropriate [CustomTag] 270 /// Process a class ([cls]). If it contains an appropriate [CustomTag]
265 /// annotation, we include an initializer to register this class, and make 271 /// annotation, we include an initializer to register this class, and make
266 /// sure to include everything that might be accessed or queried from them 272 /// sure to include everything that might be accessed or queried from them
267 /// using the smoke package. In particular, polymer uses smoke for the 273 /// using the smoke package. In particular, polymer uses smoke for the
268 /// following: 274 /// following:
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 } 823 }
818 return result; 824 return result;
819 } 825 }
820 826
821 /// Retrieves all top-level methods that are visible if you were to import 827 /// Retrieves all top-level methods that are visible if you were to import
822 /// [lib]. This includes exported methods from other libraries too. 828 /// [lib]. This includes exported methods from other libraries too.
823 List<FunctionElement> _visibleTopLevelMethodsOf(LibraryElement lib) { 829 List<FunctionElement> _visibleTopLevelMethodsOf(LibraryElement lib) {
824 var result = []; 830 var result = [];
825 result.addAll(lib.units.expand((u) => u.functions)); 831 result.addAll(lib.units.expand((u) => u.functions));
826 for (var e in lib.exports) { 832 for (var e in lib.exports) {
827 var exported = e.exportedLibrary.units 833 var exported = e.exportedLibrary.units.expand((u) => u.functions).toList();
828 .expand((u) => u.functions).toList();
829 _filter(exported, e.combinators); 834 _filter(exported, e.combinators);
830 result.addAll(exported); 835 result.addAll(exported);
831 } 836 }
832 return result; 837 return result;
833 } 838 }
834 839
835 /// Filters [elements] that come from an export, according to its show/hide 840 /// Filters [elements] that come from an export, according to its show/hide
836 /// combinators. This modifies [elements] in place. 841 /// combinators. This modifies [elements] in place.
837 void _filter(List<analyzer.Element> elements, 842 void _filter(List<analyzer.Element> elements,
838 List<NamespaceCombinator> combinators) { 843 List<NamespaceCombinator> combinators) {
839 for (var c in combinators) { 844 for (var c in combinators) {
840 if (c is ShowElementCombinator) { 845 if (c is ShowElementCombinator) {
841 var show = c.shownNames.toSet(); 846 var show = c.shownNames.toSet();
842 elements.retainWhere((e) => show.contains(e.displayName)); 847 elements.retainWhere((e) => show.contains(e.displayName));
843 } else if (c is HideElementCombinator) { 848 } else if (c is HideElementCombinator) {
844 var hide = c.hiddenNames.toSet(); 849 var hide = c.hiddenNames.toSet();
845 elements.removeWhere((e) => hide.contains(e.displayName)); 850 elements.removeWhere((e) => hide.contains(e.displayName));
846 } 851 }
847 } 852 }
848 } 853 }
OLDNEW
« no previous file with comments | « no previous file | pkg/polymer/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698