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

Side by Side Diff: pkg/polymer/lib/src/transform/polyfill_injector.dart

Issue 23678009: fixed TodoMVC tests to include deploying to JS (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 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/deploy.dart ('k') | pkg/polymer/test/transform/all_phases_test.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 /** 5 /**
6 * Final phase of the polymer transformation: includes any additional polyfills 6 * Final phase of the polymer transformation: includes any additional polyfills
7 * that may needed by the deployed app. 7 * that may needed by the deployed app.
8 */ 8 */
9 library polymer.src.transform.polyfill_injector; 9 library polymer.src.transform.polyfill_injector;
10 10
(...skipping 12 matching lines...) Expand all
23 */ 23 */
24 class PolyfillInjector extends Transformer { 24 class PolyfillInjector extends Transformer {
25 /** Only run on entry point .html files. */ 25 /** Only run on entry point .html files. */
26 Future<bool> isPrimary(Asset input) => 26 Future<bool> isPrimary(Asset input) =>
27 new Future.value(isPrimaryHtml(input.id)); 27 new Future.value(isPrimaryHtml(input.id));
28 28
29 Future apply(Transform transform) { 29 Future apply(Transform transform) {
30 return readPrimaryAsHtml(transform).then((document) { 30 return readPrimaryAsHtml(transform).then((document) {
31 bool shadowDomFound = false; 31 bool shadowDomFound = false;
32 bool jsInteropFound = false; 32 bool jsInteropFound = false;
33 bool pkgJsInteropFound = false;
33 bool dartScriptTags = false; 34 bool dartScriptTags = false;
34 35
35 for (var tag in document.queryAll('script')) { 36 for (var tag in document.queryAll('script')) {
36 var src = tag.attributes['src']; 37 var src = tag.attributes['src'];
37 if (src != null) { 38 if (src != null) {
38 var last = src.split('/').last; 39 var last = src.split('/').last;
39 if (last == 'interop.js') { 40 if (last == 'interop.js') {
40 jsInteropFound = true; 41 jsInteropFound = true;
42 } else if (last == 'dart_interop.js') {
43 pkgJsInteropFound = true;
41 } else if (_shadowDomJS.hasMatch(last)) { 44 } else if (_shadowDomJS.hasMatch(last)) {
42 shadowDomFound = true; 45 shadowDomFound = true;
43 } 46 }
44 } 47 }
45 48
46 if (tag.attributes['type'] == 'application/dart') { 49 if (tag.attributes['type'] == 'application/dart') {
47 dartScriptTags = true; 50 dartScriptTags = true;
48 } 51 }
49 } 52 }
50 53
51 if (!dartScriptTags) { 54 if (!dartScriptTags) {
52 // This HTML has no Dart code, there is nothing to do here. 55 // This HTML has no Dart code, there is nothing to do here.
53 transform.addOutput(transform.primaryInput); 56 transform.addOutput(transform.primaryInput);
54 return; 57 return;
55 } 58 }
56 59
60 if (!pkgJsInteropFound) {
61 // JS interop code is required for Polymer CSS shimming.
62 document.body.nodes.insert(0, parseFragment(
63 '<script src="packages/js/dart_interop.js"></script>\n'));
64 }
65
57 if (!jsInteropFound) { 66 if (!jsInteropFound) {
58 // JS interop code is required for Polymer CSS shimming. 67 // JS interop code is required for Polymer CSS shimming.
59 document.body.nodes.insert(0, parseFragment( 68 document.body.nodes.insert(0, parseFragment(
60 '<script src="packages/browser/interop.js"></script>\n')); 69 '<script src="packages/browser/interop.js"></script>\n'));
61 } 70 }
62 71
63 if (!shadowDomFound) { 72 if (!shadowDomFound) {
64 // Insert at the beginning (this polyfill needs to run as early as 73 // Insert at the beginning (this polyfill needs to run as early as
65 // possible). 74 // possible).
75 // TODO(jmesserly): this is .debug to workaround issue 13046.
66 document.body.nodes.insert(0, parseFragment( 76 document.body.nodes.insert(0, parseFragment(
67 '<script src="packages/shadow_dom/shadow_dom.min.js"></script>\n')); 77 '<script src="packages/shadow_dom/shadow_dom.debug.js"></script>\n') );
68 } 78 }
69 79
70 transform.addOutput( 80 transform.addOutput(
71 new Asset.fromString(transform.primaryInput.id, document.outerHtml)); 81 new Asset.fromString(transform.primaryInput.id, document.outerHtml));
72 }); 82 });
73 } 83 }
74 } 84 }
75 85
76 final _shadowDomJS = new RegExp(r'shadow_dom\..*\.js', caseSensitive: false); 86 final _shadowDomJS = new RegExp(r'shadow_dom\..*\.js', caseSensitive: false);
OLDNEW
« no previous file with comments | « pkg/polymer/lib/deploy.dart ('k') | pkg/polymer/test/transform/all_phases_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698