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

Side by Side Diff: pkg/code_transformers/lib/assets.dart

Issue 421503004: Switch transformers over to source_span (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 6 years, 4 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/code_transformers/CHANGELOG.md ('k') | pkg/code_transformers/lib/src/resolver.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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 /// Common methods used by transfomers for dealing with asset IDs. 5 /// Common methods used by transfomers for dealing with asset IDs.
6 library code_transformers.assets; 6 library code_transformers.assets;
7 7
8 import 'dart:math' show min, max; 8 import 'dart:math' show min, max;
9 9
10 import 'package:barback/barback.dart'; 10 import 'package:barback/barback.dart';
11 import 'package:path/path.dart' as path; 11 import 'package:path/path.dart' as path;
12 import 'package:source_maps/span.dart' show Span; 12 import 'package:source_span/source_span.dart';
13 13
14 /// Create an [AssetId] for a [url] seen in the [source] asset. 14 /// Create an [AssetId] for a [url] seen in the [source] asset.
15 /// 15 ///
16 /// By default this is used to resolve relative urls that occur in HTML assets, 16 /// By default this is used to resolve relative urls that occur in HTML assets,
17 /// including cross-package urls of the form "packages/foo/bar.html". Dart 17 /// including cross-package urls of the form "packages/foo/bar.html". Dart
18 /// "package:" urls are not resolved unless [source] is Dart file (has a .dart 18 /// "package:" urls are not resolved unless [source] is Dart file (has a .dart
19 /// extension). 19 /// extension).
20 /// 20 ///
21 /// This function returns null if [url] can't be resolved. We log a warning 21 /// This function returns null if [url] can't be resolved. We log a warning
22 /// message in [logger] if we know the reason why resolution failed. This 22 /// message in [logger] if we know the reason why resolution failed. This
23 /// happens, for example, when using incorrect paths to reach into another 23 /// happens, for example, when using incorrect paths to reach into another
24 /// package, or when [errorsOnAbsolute] is true and the url seems to be 24 /// package, or when [errorsOnAbsolute] is true and the url seems to be
25 /// absolute. 25 /// absolute.
26 // TODO(sigmund): delete once this is part of barback (dartbug.com/12610) 26 // TODO(sigmund): delete once this is part of barback (dartbug.com/12610)
27 AssetId uriToAssetId(AssetId source, String url, TransformLogger logger, 27 AssetId uriToAssetId(AssetId source, String url, TransformLogger logger,
28 Span span, {bool errorOnAbsolute: true}) { 28 SourceSpan span, {bool errorOnAbsolute: true}) {
29 if (url == null || url == '') return null; 29 if (url == null || url == '') return null;
30 var uri = Uri.parse(url); 30 var uri = Uri.parse(url);
31 var urlBuilder = path.url; 31 var urlBuilder = path.url;
32 if (uri.host != '' || uri.scheme != '' || urlBuilder.isAbsolute(url)) { 32 if (uri.host != '' || uri.scheme != '' || urlBuilder.isAbsolute(url)) {
33 if (source.extension == '.dart' && uri.scheme == 'package') { 33 if (source.extension == '.dart' && uri.scheme == 'package') {
34 var index = uri.path.indexOf('/'); 34 var index = uri.path.indexOf('/');
35 if (index != -1) { 35 if (index != -1) {
36 return new AssetId(uri.path.substring(0, index), 36 return new AssetId(uri.path.substring(0, index),
37 'lib${uri.path.substring(index)}'); 37 'lib${uri.path.substring(index)}');
38 } 38 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 'to: $fixedUrl', span: span); 87 'to: $fixedUrl', span: span);
88 return null; 88 return null;
89 } 89 }
90 } 90 }
91 91
92 // Otherwise, resolve as a path in the same package. 92 // Otherwise, resolve as a path in the same package.
93 return new AssetId(source.package, targetPath); 93 return new AssetId(source.package, targetPath);
94 } 94 }
95 95
96 AssetId _extractOtherPackageId(int index, List segments, 96 AssetId _extractOtherPackageId(int index, List segments,
97 TransformLogger logger, Span span) { 97 TransformLogger logger, SourceSpan span) {
98 if (index >= segments.length) return null; 98 if (index >= segments.length) return null;
99 var prefix = segments[index]; 99 var prefix = segments[index];
100 if (prefix != 'packages' && prefix != 'assets') return null; 100 if (prefix != 'packages' && prefix != 'assets') return null;
101 var folder = prefix == 'packages' ? 'lib' : 'asset'; 101 var folder = prefix == 'packages' ? 'lib' : 'asset';
102 if (segments.length < index + 3) { 102 if (segments.length < index + 3) {
103 logger.warning("incomplete $prefix/ path. It should have at least 3 " 103 logger.warning("incomplete $prefix/ path. It should have at least 3 "
104 "segments $prefix/name/path-from-name's-$folder-dir", span: span); 104 "segments $prefix/name/path-from-name's-$folder-dir", span: span);
105 return null; 105 return null;
106 } 106 }
107 return new AssetId(segments[index + 1], 107 return new AssetId(segments[index + 1],
108 path.url.join(folder, path.url.joinAll(segments.sublist(index + 2)))); 108 path.url.join(folder, path.url.joinAll(segments.sublist(index + 2))));
109 } 109 }
OLDNEW
« no previous file with comments | « pkg/code_transformers/CHANGELOG.md ('k') | pkg/code_transformers/lib/src/resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698