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

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

Issue 676313004: fix bug where dart_support.js could get included above platform.js (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: update pubspec/changelog 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 | « pkg/polymer/CHANGELOG.md ('k') | 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 /// Includes any additional polyfills that may needed by the deployed app. 5 /// Includes any additional polyfills that may needed by the deployed app.
6 library polymer.src.build.polyfill_injector; 6 library polymer.src.build.polyfill_injector;
7 7
8 import 'dart:async'; 8 import 'dart:async';
9 9
10 import 'package:barback/barback.dart'; 10 import 'package:barback/barback.dart';
(...skipping 20 matching lines...) Expand all
31 var id = idOrAsset is AssetId ? idOrAsset : idOrAsset.id; 31 var id = idOrAsset is AssetId ? idOrAsset : idOrAsset.id;
32 return new Future.value(options.isHtmlEntryPoint(id)); 32 return new Future.value(options.isHtmlEntryPoint(id));
33 } 33 }
34 34
35 Future apply(Transform transform) { 35 Future apply(Transform transform) {
36 var logger = new BuildLogger(transform, 36 var logger = new BuildLogger(transform,
37 convertErrorsToWarnings: !options.releaseMode, 37 convertErrorsToWarnings: !options.releaseMode,
38 detailsUri: 'http://goo.gl/5HPeuP'); 38 detailsUri: 'http://goo.gl/5HPeuP');
39 return readPrimaryAsHtml(transform, logger).then((document) { 39 return readPrimaryAsHtml(transform, logger).then((document) {
40 bool dartSupportFound = false; 40 bool dartSupportFound = false;
41 bool platformJsFound = false; 41 Element platformJs;
42 Element dartJs; 42 Element dartJs;
43 final dartScripts = <Element>[]; 43 final dartScripts = <Element>[];
44 44
45 for (var tag in document.querySelectorAll('script')) { 45 for (var tag in document.querySelectorAll('script')) {
46 var src = tag.attributes['src']; 46 var src = tag.attributes['src'];
47 if (src != null) { 47 if (src != null) {
48 var last = src.split('/').last; 48 var last = src.split('/').last;
49 if (_platformJS.hasMatch(last)) { 49 if (_platformJS.hasMatch(last)) {
50 platformJsFound = true; 50 platformJs = tag;
51 } else if (_dartSupportJS.hasMatch(last)) { 51 } else if (_dartSupportJS.hasMatch(last)) {
52 dartSupportFound = true; 52 dartSupportFound = true;
53 } else if (last == 'dart.js') { 53 } else if (last == 'dart.js') {
54 dartJs = tag; 54 dartJs = tag;
55 } 55 }
56 } 56 }
57 57
58 if (tag.attributes['type'] == 'application/dart') { 58 if (tag.attributes['type'] == 'application/dart') {
59 dartScripts.add(tag); 59 dartScripts.add(tag);
60 } 60 }
(...skipping 29 matching lines...) Expand all
90 } else { 90 } else {
91 document.body.nodes.add(parseFragment( 91 document.body.nodes.add(parseFragment(
92 '<script src="packages/browser/dart.js"></script>')); 92 '<script src="packages/browser/dart.js"></script>'));
93 } 93 }
94 94
95 _addScriptFirst(urlSegment) { 95 _addScriptFirst(urlSegment) {
96 document.head.nodes.insert(0, parseFragment( 96 document.head.nodes.insert(0, parseFragment(
97 '<script src="packages/$urlSegment"></script>\n')); 97 '<script src="packages/$urlSegment"></script>\n'));
98 } 98 }
99 99
100 var suffix = options.releaseMode ? '.js' : '.concat.js'; 100 // Inserts dart_support.js either at the top of the document or directly
101 if (!dartSupportFound) _addScriptFirst('web_components/dart_support.js'); 101 // after platform.js if it exists.
102 // platform.js should come before all other scripts. 102 if (!dartSupportFound) {
103 if (!platformJsFound && options.injectPlatformJs) { 103 if (platformJs == null) {
104 _addScriptFirst('web_components/dart_support.js');
105 } else {
106 var parentsNodes = platformJs.parentNode.nodes;
107 parentsNodes.insert(
108 parentsNodes.indexOf(platformJs) + 1,
109 parseFragment(
110 '\n<script src="packages/web_components/dart_support.js">'
111 '</script>'));
112 }
113 }
114
115 // By default platform.js should come before all other scripts.
116 if (platformJs == null && options.injectPlatformJs) {
117 var suffix = options.releaseMode ? '.js' : '.concat.js';
104 _addScriptFirst('web_components/platform$suffix'); 118 _addScriptFirst('web_components/platform$suffix');
105 } 119 }
106 120
107 transform.addOutput( 121 transform.addOutput(
108 new Asset.fromString(transform.primaryInput.id, document.outerHtml)); 122 new Asset.fromString(transform.primaryInput.id, document.outerHtml));
109 }); 123 });
110 } 124 }
111 } 125 }
112 126
113 final _platformJS = new RegExp(r'platform.*\.js', caseSensitive: false); 127 final _platformJS = new RegExp(r'platform.*\.js', caseSensitive: false);
114 final _dartSupportJS = new RegExp(r'dart_support.js', caseSensitive: false); 128 final _dartSupportJS = new RegExp(r'dart_support.js', caseSensitive: false);
OLDNEW
« no previous file with comments | « pkg/polymer/CHANGELOG.md ('k') | pkg/polymer/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698