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

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

Issue 993423004: Fix normalization of relative paths inside of deep relative imports (Closed) Base URL: git@github.com:dart-lang/web-components.git@master
Patch Set: format Created 5 years, 9 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
« no previous file with comments | « lib/build/import_crawler.dart ('k') | 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) 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 97
98 // Add all the other imports! 98 // Add all the other imports!
99 imports.forEach((AssetId asset, ImportData data) { 99 imports.forEach((AssetId asset, ImportData data) {
100 if (asset == primaryInput) return; 100 if (asset == primaryInput) return;
101 var document = data.document; 101 var document = data.document;
102 // Remove all dart script tags. 102 // Remove all dart script tags.
103 document 103 document
104 .querySelectorAll('script[type="$dartType"]') 104 .querySelectorAll('script[type="$dartType"]')
105 .forEach((script) => script.remove()); 105 .forEach((script) => script.remove());
106 // Normalize urls in attributes and inline css. 106 // Normalize urls in attributes and inline css.
107 new _UrlNormalizer(primaryInput, asset, logger).visit(document); 107 new _UrlNormalizer(data.fromId, asset, logger).visit(document);
108 // Replace the import with its contents by appending the nodes 108 // Replace the import with its contents by appending the nodes
109 // immediately before the import one at a time, and then removing the 109 // immediately before the import one at a time, and then removing the
110 // import from the document. 110 // import from the document.
111 var element = data.element; 111 var element = data.element;
112 var parent = element.parent; 112 var parent = element.parent;
113 document.head.nodes 113 document.head.nodes
114 .toList(growable: false) 114 .toList(growable: false)
115 .forEach((child) => parent.insertBefore(child, element)); 115 .forEach((child) => parent.insertBefore(child, element));
116 document.body.nodes 116 document.body.nodes
117 .toList(growable: false) 117 .toList(growable: false)
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 return href; 259 return href;
260 } 260 }
261 if (uri.isAbsolute) return href; 261 if (uri.isAbsolute) return href;
262 if (uri.scheme.isNotEmpty) return href; 262 if (uri.scheme.isNotEmpty) return href;
263 if (uri.host.isNotEmpty) return href; 263 if (uri.host.isNotEmpty) return href;
264 if (uri.path.isEmpty) return href; // Implies standalone ? or # in URI. 264 if (uri.path.isEmpty) return href; // Implies standalone ? or # in URI.
265 if (path.isAbsolute(hrefToParse)) return href; 265 if (path.isAbsolute(hrefToParse)) return href;
266 266
267 var id = uriToAssetId(sourceId, hrefToParse, logger, span); 267 var id = uriToAssetId(sourceId, hrefToParse, logger, span);
268 if (id == null) return href; 268 if (id == null) return href;
269 var primaryId = primaryInput;
270 269
271 // Build the new path, placing back any suffixes that we stripped earlier. 270 // Build the new path, placing back any suffixes that we stripped earlier.
272 var prefix = 271 var prefix =
273 (firstFolder == -1) ? id.path : id.path.substring(0, id.path.length); 272 (firstFolder == -1) ? id.path : id.path.substring(0, id.path.length);
274 var suffix = (firstFolder == -1) ? '' : href.substring(firstFolder); 273 var suffix = (firstFolder == -1) ? '' : href.substring(firstFolder);
275 var newPath = '$prefix$suffix'; 274 var newPath = '$prefix$suffix';
276 275
277 if (newPath.startsWith('lib/')) { 276 if (newPath.startsWith('lib/')) {
278 return '${topLevelPath}packages/${id.package}/${newPath.substring(4)}'; 277 return '${topLevelPath}packages/${id.package}/${newPath.substring(4)}';
279 } 278 }
280 279
281 if (newPath.startsWith('asset/')) { 280 if (newPath.startsWith('asset/')) {
282 return '${topLevelPath}assets/${id.package}/${newPath.substring(6)}'; 281 return '${topLevelPath}assets/${id.package}/${newPath.substring(6)}';
283 } 282 }
284 283
285 if (primaryId.package != id.package) { 284 if (primaryInput.package != id.package) {
286 // Technically we shouldn't get there 285 // Technically we shouldn't get there
287 logger.error(internalErrorDontKnowHowToImport 286 logger.error(internalErrorDontKnowHowToImport
288 .create({'target': id, 'source': primaryId, 'extra': ''}), 287 .create({'target': id, 'source': primaryInput, 'extra': ''}),
289 span: span); 288 span: span);
290 return href; 289 return href;
291 } 290 }
292 291
293 var builder = path.url; 292 var builder = path.url;
294 return builder.normalize(builder.relative(builder.join('/', newPath), 293 return builder.normalize(builder.relative(builder.join('/', newPath),
295 from: builder.join('/', builder.dirname(primaryId.path)))); 294 from: builder.join('/', builder.dirname(primaryInput.path))));
296 } 295 }
297 } 296 }
298 297
299 /// Returns true if this is a valid custom element name. See: 298 /// Returns true if this is a valid custom element name. See:
300 /// <http://w3c.github.io/webcomponents/spec/custom/#dfn-custom-element-type> 299 /// <http://w3c.github.io/webcomponents/spec/custom/#dfn-custom-element-type>
301 bool isCustomTagName(String name) { 300 bool isCustomTagName(String name) {
302 if (name == null || !name.contains('-')) return false; 301 if (name == null || !name.contains('-')) return false;
303 return !invalidTagNames.containsKey(name); 302 return !invalidTagNames.containsKey(name);
304 } 303 }
305 304
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 '_href', // in a, area, link, base, command 337 '_href', // in a, area, link, base, command
339 'icon', 338 'icon',
340 '_icon', // in command 339 '_icon', // in command
341 'manifest', 340 'manifest',
342 '_manifest', // in html 341 '_manifest', // in html
343 'poster', 342 'poster',
344 '_poster', // in video 343 '_poster', // in video
345 'src', 344 'src',
346 '_src', // in audio, embed, iframe, img, input, script, source, track,video 345 '_src', // in audio, embed, iframe, img, input, script, source, track,video
347 ]; 346 ];
OLDNEW
« no previous file with comments | « lib/build/import_crawler.dart ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698