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

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

Issue 24046003: Fix TODO in polymer _shimCss, remove package:js dependency (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
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 16 matching lines...) Expand all
27 PolyfillInjector(this.options); 27 PolyfillInjector(this.options);
28 28
29 /** Only run on entry point .html files. */ 29 /** Only run on entry point .html files. */
30 Future<bool> isPrimary(Asset input) => 30 Future<bool> isPrimary(Asset input) =>
31 new Future.value(options.isHtmlEntryPoint(input.id)); 31 new Future.value(options.isHtmlEntryPoint(input.id));
32 32
33 Future apply(Transform transform) { 33 Future apply(Transform transform) {
34 return readPrimaryAsHtml(transform).then((document) { 34 return readPrimaryAsHtml(transform).then((document) {
35 bool shadowDomFound = false; 35 bool shadowDomFound = false;
36 bool jsInteropFound = false; 36 bool jsInteropFound = false;
37 bool pkgJsInteropFound = false;
38 bool dartScriptTags = false; 37 bool dartScriptTags = false;
39 38
40 for (var tag in document.queryAll('script')) { 39 for (var tag in document.queryAll('script')) {
41 var src = tag.attributes['src']; 40 var src = tag.attributes['src'];
42 if (src != null) { 41 if (src != null) {
43 var last = src.split('/').last; 42 var last = src.split('/').last;
44 if (last == 'interop.js') { 43 if (last == 'interop.js') {
45 jsInteropFound = true; 44 jsInteropFound = true;
46 } else if (last == 'dart_interop.js') {
47 pkgJsInteropFound = true;
48 } else if (_shadowDomJS.hasMatch(last)) { 45 } else if (_shadowDomJS.hasMatch(last)) {
49 shadowDomFound = true; 46 shadowDomFound = true;
50 } 47 }
51 } 48 }
52 49
53 if (tag.attributes['type'] == 'application/dart') { 50 if (tag.attributes['type'] == 'application/dart') {
54 dartScriptTags = true; 51 dartScriptTags = true;
55 } 52 }
56 } 53 }
57 54
58 if (!dartScriptTags) { 55 if (!dartScriptTags) {
59 // This HTML has no Dart code, there is nothing to do here. 56 // This HTML has no Dart code, there is nothing to do here.
60 transform.addOutput(transform.primaryInput); 57 transform.addOutput(transform.primaryInput);
61 return; 58 return;
62 } 59 }
63 60
64 if (!pkgJsInteropFound) {
65 // JS interop code is required for Polymer CSS shimming.
66 document.body.nodes.insert(0, parseFragment(
67 '<script src="packages/js/dart_interop.js"></script>\n'));
68 }
69
70 if (!jsInteropFound) { 61 if (!jsInteropFound) {
71 // JS interop code is required for Polymer CSS shimming. 62 // JS interop code is required for Polymer CSS shimming.
72 document.body.nodes.insert(0, parseFragment( 63 document.body.nodes.insert(0, parseFragment(
73 '<script src="packages/browser/interop.js"></script>\n')); 64 '<script src="packages/browser/interop.js"></script>\n'));
74 } 65 }
75 66
76 if (!shadowDomFound) { 67 if (!shadowDomFound) {
77 // Insert at the beginning (this polyfill needs to run as early as 68 // Insert at the beginning (this polyfill needs to run as early as
78 // possible). 69 // possible).
79 // TODO(jmesserly): this is .debug to workaround issue 13046. 70 // TODO(jmesserly): this is .debug to workaround issue 13046.
80 document.body.nodes.insert(0, parseFragment( 71 document.body.nodes.insert(0, parseFragment(
81 '<script src="packages/shadow_dom/shadow_dom.debug.js"></script>\n') ); 72 '<script src="packages/shadow_dom/shadow_dom.debug.js"></script>\n') );
82 } 73 }
83 74
84 transform.addOutput( 75 transform.addOutput(
85 new Asset.fromString(transform.primaryInput.id, document.outerHtml)); 76 new Asset.fromString(transform.primaryInput.id, document.outerHtml));
86 }); 77 });
87 } 78 }
88 } 79 }
89 80
90 final _shadowDomJS = new RegExp(r'shadow_dom\..*\.js', caseSensitive: false); 81 final _shadowDomJS = new RegExp(r'shadow_dom\..*\.js', caseSensitive: false);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698