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

Side by Side Diff: packages/web_components/lib/build/import_inliner.dart

Issue 2312183003: Removed Polymer from Observatory deps (Closed)
Patch Set: Created 4 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
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 library web_components.build.import_inliner; 4 library web_components.build.import_inliner;
5 5
6 import 'dart:async'; 6 import 'dart:async';
7 import 'dart:collection' show LinkedHashMap; 7 import 'dart:collection' show LinkedHashMap;
8 import 'package:barback/barback.dart'; 8 import 'package:barback/barback.dart';
9 import 'package:code_transformers/assets.dart'; 9 import 'package:code_transformers/assets.dart';
10 import 'package:code_transformers/messages/build_logger.dart'; 10 import 'package:code_transformers/messages/build_logger.dart';
(...skipping 20 matching lines...) Expand all
31 if (entryPoints != null) return entryPoints.contains(id.path); 31 if (entryPoints != null) return entryPoints.contains(id.path);
32 // If no entry point is supplied, then any html file under web/ or test/ is 32 // If no entry point is supplied, then any html file under web/ or test/ is
33 // an entry point. 33 // an entry point.
34 return (id.path.startsWith('web/') || id.path.startsWith('test/')) && 34 return (id.path.startsWith('web/') || id.path.startsWith('test/')) &&
35 id.path.endsWith('.html'); 35 id.path.endsWith('.html');
36 } 36 }
37 37
38 apply(Transform transform) { 38 apply(Transform transform) {
39 var logger = new BuildLogger(transform, convertErrorsToWarnings: true); 39 var logger = new BuildLogger(transform, convertErrorsToWarnings: true);
40 return new ImportInliner(transform, transform.primaryInput.id, logger, 40 return new ImportInliner(transform, transform.primaryInput.id, logger,
41 bindingStartDelimiters: bindingStartDelimiters).run(); 41 bindingStartDelimiters: bindingStartDelimiters)
42 .run();
42 } 43 }
43 } 44 }
44 45
45 /// Helper class which actually does all the inlining of html imports for a 46 /// Helper class which actually does all the inlining of html imports for a
46 /// single entry point. 47 /// single entry point.
47 class ImportInliner { 48 class ImportInliner {
48 // Can be an AggregateTransform or Transform 49 // Can be an AggregateTransform or Transform
49 final transform; 50 final transform;
50 // The primary input to start from. 51 // The primary input to start from.
51 final AssetId primaryInput; 52 final AssetId primaryInput;
(...skipping 12 matching lines...) Expand all
64 65
65 // Normalize urls in the entry point. 66 // Normalize urls in the entry point.
66 var changed = new _UrlNormalizer( 67 var changed = new _UrlNormalizer(
67 primaryInput, primaryInput, logger, bindingStartDelimiters) 68 primaryInput, primaryInput, logger, bindingStartDelimiters)
68 .visit(primaryDocument); 69 .visit(primaryDocument);
69 70
70 // Inline things if needed, always have at least one (the entry point). 71 // Inline things if needed, always have at least one (the entry point).
71 if (imports.length > 1) { 72 if (imports.length > 1) {
72 _inlineImports(primaryDocument, imports); 73 _inlineImports(primaryDocument, imports);
73 } else if (!changed && 74 } else if (!changed &&
74 primaryDocument.querySelectorAll('link[rel="import"]').where( 75 primaryDocument
75 (import) => import.attributes['type'] != 'css').length == 76 .querySelectorAll('link[rel="import"]')
77 .where((import) => import.attributes['type'] != 'css')
78 .length ==
76 0) { 79 0) {
77 // If there were no url changes and no imports, then we are done. 80 // If there were no url changes and no imports, then we are done.
78 return; 81 return;
79 } 82 }
80 83
81 primaryDocument 84 primaryDocument
82 .querySelectorAll('link[rel="import"]') 85 .querySelectorAll('link[rel="import"]')
83 .where((import) => import.attributes['type'] != 'css') 86 .where((import) => import.attributes['type'] != 'css')
84 .forEach((element) => element.remove()); 87 .forEach((element) => element.remove());
85 88
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 // polymer package. We should consolidate this logic by either removing it 169 // polymer package. We should consolidate this logic by either removing it
167 // completely from polymer or exposing it publicly here and using that in 170 // completely from polymer or exposing it publicly here and using that in
168 // polymer. 171 // polymer.
169 class _UrlNormalizer extends TreeVisitor { 172 class _UrlNormalizer extends TreeVisitor {
170 /// [AssetId] for the main entry point. 173 /// [AssetId] for the main entry point.
171 final AssetId primaryInput; 174 final AssetId primaryInput;
172 175
173 /// Asset where the original content (and original url) was found. 176 /// Asset where the original content (and original url) was found.
174 final AssetId sourceId; 177 final AssetId sourceId;
175 178
176 /// Counter used to ensure that every library name we inject is unique.
177 int _count = 0;
178
179 /// Path to the top level folder relative to the transform primaryInput. 179 /// Path to the top level folder relative to the transform primaryInput.
180 /// This should just be some arbitrary # of ../'s. 180 /// This should just be some arbitrary # of ../'s.
181 final String topLevelPath; 181 final String topLevelPath;
182 182
183 /// Whether or not the normalizer has changed something in the tree. 183 /// Whether or not the normalizer has changed something in the tree.
184 bool changed = false; 184 bool changed = false;
185 185
186 // The start delimiters for template bindings, such as '{{' or '[['. If these 186 // The start delimiters for template bindings, such as '{{' or '[['. If these
187 // are found before the first `/` in a url, then the url will not be 187 // are found before the first `/` in a url, then the url will not be
188 // normalized. 188 // normalized.
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 if (newPath.startsWith('lib/')) { 296 if (newPath.startsWith('lib/')) {
297 return '${topLevelPath}packages/${id.package}/${newPath.substring(4)}'; 297 return '${topLevelPath}packages/${id.package}/${newPath.substring(4)}';
298 } 298 }
299 299
300 if (newPath.startsWith('asset/')) { 300 if (newPath.startsWith('asset/')) {
301 return '${topLevelPath}assets/${id.package}/${newPath.substring(6)}'; 301 return '${topLevelPath}assets/${id.package}/${newPath.substring(6)}';
302 } 302 }
303 303
304 if (primaryInput.package != id.package) { 304 if (primaryInput.package != id.package) {
305 // Technically we shouldn't get there 305 // Technically we shouldn't get there
306 logger.error(internalErrorDontKnowHowToImport 306 logger.error(
307 internalErrorDontKnowHowToImport
307 .create({'target': id, 'source': primaryInput, 'extra': ''}), 308 .create({'target': id, 'source': primaryInput, 'extra': ''}),
308 span: span); 309 span: span);
309 return href; 310 return href;
310 } 311 }
311 312
312 var builder = path.url; 313 var builder = path.url;
313 return builder.normalize(builder.relative(builder.join('/', newPath), 314 return builder.normalize(builder.relative(builder.join('/', newPath),
314 from: builder.join('/', builder.dirname(primaryInput.path)))); 315 from: builder.join('/', builder.dirname(primaryInput.path))));
315 } 316 }
316 } 317 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 '_href', // in a, area, link, base, command 358 '_href', // in a, area, link, base, command
358 'icon', 359 'icon',
359 '_icon', // in command 360 '_icon', // in command
360 'manifest', 361 'manifest',
361 '_manifest', // in html 362 '_manifest', // in html
362 'poster', 363 'poster',
363 '_poster', // in video 364 '_poster', // in video
364 'src', 365 'src',
365 '_src', // in audio, embed, iframe, img, input, script, source, track,video 366 '_src', // in audio, embed, iframe, img, input, script, source, track,video
366 ]; 367 ];
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698