Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 | 2 |
| 3 // for details. All rights reserved. Use of this source code is governed by a | 3 // for details. All rights reserved. Use of this source code is governed by a |
| 4 // BSD-style license that can be found in the LICENSE file. | 4 // BSD-style license that can be found in the LICENSE file. |
| 5 | 5 |
| 6 import 'dart:collection' show HashMap, HashSet; | 6 import 'dart:collection' show HashMap, HashSet; |
| 7 import 'dart:math' show min, max; | 7 import 'dart:math' show min, max; |
| 8 | 8 |
| 9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; | 9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; |
| 10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| (...skipping 6015 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6026 } | 6026 } |
| 6027 // TODO(vsm): This is not necessarily unique if '__' appears in a file name. | 6027 // TODO(vsm): This is not necessarily unique if '__' appears in a file name. |
| 6028 var encodedSeparator = '__'; | 6028 var encodedSeparator = '__'; |
| 6029 String qualifiedPath; | 6029 String qualifiedPath; |
| 6030 if (uri.scheme == 'package') { | 6030 if (uri.scheme == 'package') { |
| 6031 // Strip the package name. | 6031 // Strip the package name. |
| 6032 // TODO(vsm): This is not unique if an escaped '/'appears in a filename. | 6032 // TODO(vsm): This is not unique if an escaped '/'appears in a filename. |
| 6033 // E.g., "foo/bar.dart" and "foo$47bar.dart" would collide. | 6033 // E.g., "foo/bar.dart" and "foo$47bar.dart" would collide. |
| 6034 qualifiedPath = uri.pathSegments.skip(1).join(encodedSeparator); | 6034 qualifiedPath = uri.pathSegments.skip(1).join(encodedSeparator); |
| 6035 } else if (isWithin(libraryRoot, uri.toFilePath())) { | 6035 } else if (isWithin(libraryRoot, uri.toFilePath())) { |
| 6036 qualifiedPath = uri.path | 6036 qualifiedPath = uri |
| 6037 .toFilePath() | |
| 6037 .substring(libraryRoot.length) | 6038 .substring(libraryRoot.length) |
|
jakemac
2017/05/24 18:25:17
Should we change this to use `path.relative` as we
| |
| 6038 .replaceAll(separator, encodedSeparator); | 6039 .replaceAll(separator, encodedSeparator); |
| 6039 } else { | 6040 } else { |
| 6040 // We don't have a unique name. | 6041 // We don't have a unique name. |
| 6041 throw 'Invalid library root. $libraryRoot does not contain ${uri | 6042 throw 'Invalid library root. $libraryRoot does not contain ${uri |
| 6042 .toFilePath()}'; | 6043 .toFilePath()}'; |
| 6043 } | 6044 } |
| 6044 return pathToJSIdentifier(qualifiedPath); | 6045 return pathToJSIdentifier(qualifiedPath); |
| 6045 } | 6046 } |
| 6046 | 6047 |
| 6047 /// Debugger friendly name for a Dart Library. | 6048 /// Debugger friendly name for a Dart Library. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6128 if (targetIdentifier.staticElement is! PrefixElement) return false; | 6129 if (targetIdentifier.staticElement is! PrefixElement) return false; |
| 6129 var prefix = targetIdentifier.staticElement as PrefixElement; | 6130 var prefix = targetIdentifier.staticElement as PrefixElement; |
| 6130 | 6131 |
| 6131 // The library the prefix is referring to must come from a deferred import. | 6132 // The library the prefix is referring to must come from a deferred import. |
| 6132 var containingLibrary = resolutionMap | 6133 var containingLibrary = resolutionMap |
| 6133 .elementDeclaredByCompilationUnit(target.root as CompilationUnit) | 6134 .elementDeclaredByCompilationUnit(target.root as CompilationUnit) |
| 6134 .library; | 6135 .library; |
| 6135 var imports = containingLibrary.getImportsWithPrefix(prefix); | 6136 var imports = containingLibrary.getImportsWithPrefix(prefix); |
| 6136 return imports.length == 1 && imports[0].isDeferred; | 6137 return imports.length == 1 && imports[0].isDeferred; |
| 6137 } | 6138 } |
| OLD | NEW |