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

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

Issue 239433012: Detect and warn about missing scripts (rather than fail during the build) (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 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
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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 logger.warning('unexpected script. The ' 132 logger.warning('unexpected script. The '
133 'ScriptCompactor transformer should run after running the ' 133 'ScriptCompactor transformer should run after running the '
134 'ImportInliner', span: tag.sourceSpan); 134 'ImportInliner', span: tag.sourceSpan);
135 } 135 }
136 } 136 }
137 } 137 }
138 138
139 /// Emits the main HTML and Dart bootstrap code for the application. If there 139 /// 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. 140 /// were not Dart entry point files, then this simply emits the original HTML.
141 Future _emitNewEntrypoint(_) { 141 Future _emitNewEntrypoint(_) {
142 if (entryLibraries.isEmpty) { 142 // If we don't find code, there is nothing to do.
143 // We didn't find code, nothing to do. 143 if (entryLibraries.isEmpty) return null;
144 transform.addOutput(transform.primaryInput);
145 return null;
146 }
147
148 return _initResolver() 144 return _initResolver()
149 .then(_extractUsesOfMirrors) 145 .then(_extractUsesOfMirrors)
150 .then(_emitFiles) 146 .then(_emitFiles)
151 .whenComplete(() { 147 .whenComplete(() {
152 if (resolver != null) resolver.release(); 148 if (resolver != null) resolver.release();
153 }); 149 });
154 } 150 }
155 151
156 /// Load a resolver that computes information for every library in 152 /// Load a resolver that computes information for every library in
157 /// [entryLibraries], then use it to initialize the [recorder] (for import 153 /// [entryLibraries], then use it to initialize the [recorder] (for import
158 /// resolution) and to resolve specific elements (for analyzing the user's 154 /// resolution) and to resolve specific elements (for analyzing the user's
159 /// code). 155 /// code).
160 Future _initResolver() => resolvers.get(transform, entryLibraries).then((r) { 156 Future _initResolver() {
161 resolver = r; 157 // We include 'polymer.dart' to simplify how we do resolution below. This
162 types = new _ResolvedTypes(resolver); 158 // way we can assume polymer is there, even if the user didn't include an
163 }); 159 // import to it.
160 var libsToLoad = [new AssetId('polymer', 'lib/polymer.dart')]
Jennifer Messerly 2014/04/18 00:53:33 based on the test, is the idea here that we don't
Siggi Cherem (dart-lang) 2014/04/18 01:05:16 Right
161 ..addAll(entryLibraries);
162 return resolvers.get(transform, libsToLoad).then((r) {
163 resolver = r;
164 types = new _ResolvedTypes(resolver);
165 });
166 }
164 167
165 /// Inspects the entire program to find out anything that polymer accesses 168 /// Inspects the entire program to find out anything that polymer accesses
166 /// using mirrors and produces static information that can be used to replace 169 /// using mirrors and produces static information that can be used to replace
167 /// the mirror-based loader and the uses of mirrors through the `smoke` 170 /// the mirror-based loader and the uses of mirrors through the `smoke`
168 /// package. This includes: 171 /// package. This includes:
169 /// 172 ///
170 /// * visiting entry-libraries to extract initializers, 173 /// * visiting entry-libraries to extract initializers,
171 /// * visiting polymer-expressions to extract getters and setters, 174 /// * visiting polymer-expressions to extract getters and setters,
172 /// * looking for published fields of custom elements, and 175 /// * looking for published fields of custom elements, and
173 /// * looking for event handlers and callbacks of change notifications. 176 /// * looking for event handlers and callbacks of change notifications.
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 code.writeln("import '$url' as i$i;"); 341 code.writeln("import '$url' as i$i;");
339 prefixes[id] = 'i$i'; 342 prefixes[id] = 'i$i';
340 i++; 343 i++;
341 } 344 }
342 345
343 // Include smoke initialization. 346 // Include smoke initialization.
344 generator.writeImports(code); 347 generator.writeImports(code);
345 generator.writeTopLevelDeclarations(code); 348 generator.writeTopLevelDeclarations(code);
346 code.writeln('\nvoid main() {'); 349 code.writeln('\nvoid main() {');
347 generator.writeInitCall(code); 350 generator.writeInitCall(code);
348 code.writeln(' startPolymer(['); 351 code.write(' startPolymer([');
349 352
350 // Include initializers to switch from mirrors_loader to static_loader. 353 // Include initializers to switch from mirrors_loader to static_loader.
351 for (var init in initializers) { 354 if (!initializers.isEmpty) {
352 var initCode = init.asCode(prefixes[init.assetId]); 355 code.writeln();
353 code.write(" $initCode,\n"); 356 for (var init in initializers) {
357 var initCode = init.asCode(prefixes[init.assetId]);
358 code.write(" $initCode,\n");
359 }
360 code.writeln(' ]);');
361 } else {
362 logger.warning('no polymer initializers were found.');
Jennifer Messerly 2014/04/18 00:53:33 I wonder if we should add more to this msg about h
Siggi Cherem (dart-lang) 2014/04/18 01:05:16 Good idea. Done.
363 code.writeln(']);');
354 } 364 }
355 code..writeln(' ]);') 365 code.writeln('}');
356 ..writeln('}');
357 transform.addOutput(new Asset.fromString(bootstrapId, code.toString())); 366 transform.addOutput(new Asset.fromString(bootstrapId, code.toString()));
358 367
359 368
360 // Emit the bootstrap .dart file 369 // Emit the bootstrap .dart file
361 var srcUrl = path.url.basename(bootstrapId.path); 370 var srcUrl = path.url.basename(bootstrapId.path);
362 document.body.nodes.add(parseFragment( 371 document.body.nodes.add(parseFragment(
363 '<script type="application/dart" src="$srcUrl"></script>')); 372 '<script type="application/dart" src="$srcUrl"></script>'));
364 transform.addOutput(new Asset.fromString(docId, document.outerHtml)); 373 transform.addOutput(new Asset.fromString(docId, document.outerHtml));
365 } 374 }
366 375
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 for (var c in combinators) { 698 for (var c in combinators) {
690 if (c is ShowElementCombinator) { 699 if (c is ShowElementCombinator) {
691 var show = c.shownNames.toSet(); 700 var show = c.shownNames.toSet();
692 elements.retainWhere((e) => show.contains(e.displayName)); 701 elements.retainWhere((e) => show.contains(e.displayName));
693 } else if (c is HideElementCombinator) { 702 } else if (c is HideElementCombinator) {
694 var hide = c.hiddenNames.toSet(); 703 var hide = c.hiddenNames.toSet();
695 elements.removeWhere((e) => hide.contains(e.displayName)); 704 elements.removeWhere((e) => hide.contains(e.displayName));
696 } 705 }
697 } 706 }
698 } 707 }
OLDNEW
« no previous file with comments | « pkg/polymer/lib/src/build/import_inliner.dart ('k') | pkg/polymer/test/build/code_extractor.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698