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

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

Issue 293023008: Bring back initPolymer, allow boot.js only if using "polymer_experimental.html". (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 months 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 | « pkg/polymer/lib/src/build/mirrors_remover.dart ('k') | pkg/polymer/lib/src/declaration.dart » ('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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 final AssetId docId; 67 final AssetId docId;
68 final AssetId bootstrapId; 68 final AssetId bootstrapId;
69 69
70 /// HTML document parsed from [docId]. 70 /// HTML document parsed from [docId].
71 Document document; 71 Document document;
72 72
73 /// List of ids for each Dart entry script tag (the main tag and any tag 73 /// List of ids for each Dart entry script tag (the main tag and any tag
74 /// included on each custom element definition). 74 /// included on each custom element definition).
75 List<AssetId> entryLibraries; 75 List<AssetId> entryLibraries;
76 76
77 /// Whether we are using the experimental bootstrap logic.
78 bool experimentalBootstrap;
79
77 /// Initializers that will register custom tags or invoke `initMethod`s. 80 /// Initializers that will register custom tags or invoke `initMethod`s.
78 final List<_Initializer> initializers = []; 81 final List<_Initializer> initializers = [];
79 82
80 /// Attributes published on a custom-tag. We make these available via 83 /// Attributes published on a custom-tag. We make these available via
81 /// reflection even if @published was not used. 84 /// reflection even if @published was not used.
82 final Map<String, List<String>> publishedAttributes = {}; 85 final Map<String, List<String>> publishedAttributes = {};
83 86
84 /// Hook needed to access the analyzer within barback transformers. 87 /// Hook needed to access the analyzer within barback transformers.
85 final Resolvers resolvers; 88 final Resolvers resolvers;
86 89
(...skipping 17 matching lines...) Expand all
104 .then(_loadEntryLibraries) 107 .then(_loadEntryLibraries)
105 .then(_processHtml) 108 .then(_processHtml)
106 .then(_emitNewEntrypoint); 109 .then(_emitNewEntrypoint);
107 110
108 /// Loads the primary input as an html document. 111 /// Loads the primary input as an html document.
109 Future _loadDocument() => 112 Future _loadDocument() =>
110 readPrimaryAsHtml(transform).then((doc) { document = doc; }); 113 readPrimaryAsHtml(transform).then((doc) { document = doc; });
111 114
112 /// Populates [entryLibraries] as a list containing the asset ids of each 115 /// Populates [entryLibraries] as a list containing the asset ids of each
113 /// library loaded on a script tag. The actual work of computing this is done 116 /// library loaded on a script tag. The actual work of computing this is done
114 /// in an earlier phase and emited in the `entrypoint.scriptUrls` asset. 117 /// in an earlier phase and emited in the `entrypoint._data` asset.
115 Future _loadEntryLibraries(_) => 118 Future _loadEntryLibraries(_) =>
116 transform.readInputAsString(docId.addExtension('.scriptUrls')) 119 transform.readInputAsString(docId.addExtension('._data')).then((data) {
117 .then((libraryIds) { 120 var map = JSON.decode(data);
118 entryLibraries = (JSON.decode(libraryIds) as Iterable) 121 experimentalBootstrap = map['experimental_bootstrap'];
119 .map((data) => new AssetId.deserialize(data)).toList(); 122 entryLibraries = map['script_ids']
123 .map((id) => new AssetId.deserialize(id))
124 .toList();
120 }); 125 });
121 126
122 /// Removes unnecessary script tags, and identifies the main entry point Dart 127 /// Removes unnecessary script tags, and identifies the main entry point Dart
123 /// script tag (if any). 128 /// script tag (if any).
124 void _processHtml(_) { 129 void _processHtml(_) {
125 for (var tag in document.querySelectorAll('script')) { 130 for (var tag in document.querySelectorAll('script')) {
126 var src = tag.attributes['src']; 131 var src = tag.attributes['src'];
127 if (src == 'packages/polymer/boot.js') { 132 if (src == 'packages/polymer/boot.js') {
128 tag.remove(); 133 tag.remove();
129 continue; 134 continue;
130 } 135 }
131 if (tag.attributes['type'] == 'application/dart;component=1') { 136 if (tag.attributes['type'] == 'application/dart') {
132 logger.warning('unexpected script. The ' 137 logger.warning('unexpected script. The '
133 'ScriptCompactor transformer should run after running the ' 138 'ScriptCompactor transformer should run after running the '
134 'ImportInliner', span: tag.sourceSpan); 139 'ImportInliner', span: tag.sourceSpan);
135 } 140 }
136 } 141 }
137 } 142 }
138 143
139 /// Emits the main HTML and Dart bootstrap code for the application. If there 144 /// Emits the main HTML and Dart bootstrap code for the application. If there
140 /// were not Dart entry point files, then this simply emits the original HTML. 145 /// were not Dart entry point files, then this simply emits the original HTML.
141 Future _emitNewEntrypoint(_) { 146 Future _emitNewEntrypoint(_) {
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 code.writeln("import '$url' as i$i;"); 348 code.writeln("import '$url' as i$i;");
344 prefixes[id] = 'i$i'; 349 prefixes[id] = 'i$i';
345 i++; 350 i++;
346 } 351 }
347 352
348 // Include smoke initialization. 353 // Include smoke initialization.
349 generator.writeImports(code); 354 generator.writeImports(code);
350 generator.writeTopLevelDeclarations(code); 355 generator.writeTopLevelDeclarations(code);
351 code.writeln('\nvoid main() {'); 356 code.writeln('\nvoid main() {');
352 generator.writeInitCall(code); 357 generator.writeInitCall(code);
353 code.write(' startPolymer(['); 358 if (experimentalBootstrap) {
359 code.write(' startPolymer([');
360 } else {
361 code.write(' configureForDeployment([');
362 }
354 363
355 // Include initializers to switch from mirrors_loader to static_loader. 364 // Include initializers to switch from mirrors_loader to static_loader.
356 if (!initializers.isEmpty) { 365 if (!initializers.isEmpty) {
357 code.writeln(); 366 code.writeln();
358 for (var init in initializers) { 367 for (var init in initializers) {
359 var initCode = init.asCode(prefixes[init.assetId]); 368 var initCode = init.asCode(prefixes[init.assetId]);
360 code.write(" $initCode,\n"); 369 code.write(" $initCode,\n");
361 } 370 }
362 code.writeln(' ]);'); 371 code.writeln(' ]);');
363 } else { 372 } else {
364 logger.warning(NO_INITIALIZERS_ERROR); 373 if (experimentalBootstrap) logger.warning(NO_INITIALIZERS_ERROR);
365 code.writeln(']);'); 374 code.writeln(']);');
366 } 375 }
376 if (!experimentalBootstrap) {
377 code.writeln(' i${entryLibraries.length - 1}.main();');
378 }
367 code.writeln('}'); 379 code.writeln('}');
368 transform.addOutput(new Asset.fromString(bootstrapId, code.toString())); 380 transform.addOutput(new Asset.fromString(bootstrapId, code.toString()));
369 381
370 382
371 // Emit the bootstrap .dart file 383 // Emit the bootstrap .dart file
372 var srcUrl = path.url.basename(bootstrapId.path); 384 var srcUrl = path.url.basename(bootstrapId.path);
373 document.body.nodes.add(parseFragment( 385 document.body.nodes.add(parseFragment(
374 '<script type="application/dart" src="$srcUrl"></script>')); 386 '<script type="application/dart" src="$srcUrl"></script>'));
375 transform.addOutput(new Asset.fromString(docId, document.outerHtml)); 387 transform.addOutput(new Asset.fromString(docId, document.outerHtml));
376 } 388 }
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 for (var c in combinators) { 719 for (var c in combinators) {
708 if (c is ShowElementCombinator) { 720 if (c is ShowElementCombinator) {
709 var show = c.shownNames.toSet(); 721 var show = c.shownNames.toSet();
710 elements.retainWhere((e) => show.contains(e.displayName)); 722 elements.retainWhere((e) => show.contains(e.displayName));
711 } else if (c is HideElementCombinator) { 723 } else if (c is HideElementCombinator) {
712 var hide = c.hiddenNames.toSet(); 724 var hide = c.hiddenNames.toSet();
713 elements.removeWhere((e) => hide.contains(e.displayName)); 725 elements.removeWhere((e) => hide.contains(e.displayName));
714 } 726 }
715 } 727 }
716 } 728 }
OLDNEW
« no previous file with comments | « pkg/polymer/lib/src/build/mirrors_remover.dart ('k') | pkg/polymer/lib/src/declaration.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698