| OLD | NEW |
| 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 * Datatypes holding information extracted by the analyzer and used by later | 6 * Datatypes holding information extracted by the analyzer and used by later |
| 7 * phases of the compiler. | 7 * phases of the compiler. |
| 8 */ | 8 */ |
| 9 library polymer.src.info; | 9 library polymer.src.info; |
| 10 | 10 |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 final Span sourceSpan; | 286 final Span sourceSpan; |
| 287 | 287 |
| 288 UrlInfo(this.url, this.resolvedPath, this.sourceSpan); | 288 UrlInfo(this.url, this.resolvedPath, this.sourceSpan); |
| 289 | 289 |
| 290 /** | 290 /** |
| 291 * Resolve a path from an [url] found in a file located at [inputUrl]. | 291 * Resolve a path from an [url] found in a file located at [inputUrl]. |
| 292 * Returns null for absolute [url]. Unless [ignoreAbsolute] is true, reports | 292 * Returns null for absolute [url]. Unless [ignoreAbsolute] is true, reports |
| 293 * an error message if the url is an absolute url. | 293 * an error message if the url is an absolute url. |
| 294 */ | 294 */ |
| 295 static UrlInfo resolve(String url, UrlInfo inputUrl, Span span, | 295 static UrlInfo resolve(String url, UrlInfo inputUrl, Span span, |
| 296 String packageRoot, Messages messages, {bool ignoreAbsolute: false}) { | 296 Messages messages, {bool ignoreAbsolute: false}) { |
| 297 | 297 |
| 298 var uri = Uri.parse(url); | 298 var uri = Uri.parse(url); |
| 299 if (uri.host != '' || (uri.scheme != '' && uri.scheme != 'package')) { | 299 if (uri.host != '' || (uri.scheme != '') || path.isAbsolute(url)) { |
| 300 if (!ignoreAbsolute) { | 300 if (!ignoreAbsolute) { |
| 301 messages.error('absolute paths not allowed here: "$url"', span); | 301 messages.error('absolute paths not allowed here: "$url"', span); |
| 302 } | 302 } |
| 303 return null; | 303 return null; |
| 304 } | 304 } |
| 305 | 305 |
| 306 var target; | 306 var target = path.normalize( |
| 307 if (url.startsWith('package:')) { | 307 path.join(path.dirname(inputUrl.resolvedPath), url)); |
| 308 target = path.join(packageRoot, url.substring(8)); | 308 url = pathToUrl(path.normalize(path.join(path.dirname(inputUrl.url), url))); |
| 309 } else if (path.isAbsolute(url)) { | |
| 310 if (!ignoreAbsolute) { | |
| 311 messages.error('absolute paths not allowed here: "$url"', span); | |
| 312 } | |
| 313 return null; | |
| 314 } else { | |
| 315 target = path.join(path.dirname(inputUrl.resolvedPath), url); | |
| 316 url = pathToUrl(path.normalize(path.join( | |
| 317 path.dirname(inputUrl.url), url))); | |
| 318 } | |
| 319 target = path.normalize(target); | |
| 320 | |
| 321 return new UrlInfo(url, target, span); | 309 return new UrlInfo(url, target, span); |
| 322 } | 310 } |
| 323 | 311 |
| 324 bool operator ==(UrlInfo other) => | 312 bool operator ==(UrlInfo other) => |
| 325 url == other.url && resolvedPath == other.resolvedPath; | 313 url == other.url && resolvedPath == other.resolvedPath; |
| 326 | 314 |
| 327 int get hashCode => resolvedPath.hashCode; | 315 int get hashCode => resolvedPath.hashCode; |
| 328 | 316 |
| 329 String toString() => "#<UrlInfo url: $url, resolvedPath: $resolvedPath>"; | 317 String toString() => "#<UrlInfo url: $url, resolvedPath: $resolvedPath>"; |
| 330 } | 318 } |
| OLD | NEW |