Index: pkg/front_end/lib/src/fasta/uri_translator_impl.dart |
diff --git a/pkg/front_end/lib/src/fasta/uri_translator_impl.dart b/pkg/front_end/lib/src/fasta/uri_translator_impl.dart |
index df58a966875921a0cd048fa3a2e849f105f688d8..d94a69c15b8d7e05ae0a9010f865317bfe9247ea 100644 |
--- a/pkg/front_end/lib/src/fasta/uri_translator_impl.dart |
+++ b/pkg/front_end/lib/src/fasta/uri_translator_impl.dart |
@@ -11,6 +11,8 @@ import 'package:front_end/file_system.dart' |
show FileSystem, FileSystemException; |
import 'package:front_end/src/fasta/uri_translator.dart'; |
import 'package:package_config/packages_file.dart' as packages_file show parse; |
+import 'package:package_config/packages.dart' show Packages; |
+import 'package:package_config/src/packages_impl.dart' show MapPackages; |
import 'deprecated_problems.dart' show deprecated_inputError; |
@@ -46,7 +48,7 @@ class UriTranslatorImpl implements UriTranslator { |
final Map<String, List<Uri>> dartPatches; |
/// Mapping from package names (e.g. `angular`) to the file URIs. |
- final Map<String, Uri> packages; |
+ final Packages packages; |
UriTranslatorImpl(this.dartLibraries, this.dartPatches, this.packages); |
@@ -86,13 +88,14 @@ class UriTranslatorImpl implements UriTranslator { |
/// `null` if the `package` [uri] format is invalid, or there is no |
/// corresponding package registered. |
Uri _translatePackageUri(Uri uri) { |
- int index = uri.path.indexOf("/"); |
- if (index == -1) return null; |
- String name = uri.path.substring(0, index); |
- String path = uri.path.substring(index + 1); |
- Uri root = packages[name]; |
- if (root == null) return null; |
- return root.resolve(path); |
+ try { |
+ // TODO(sigmund): once we remove the `parse` API, we can ensure that |
+ // packages will never be null and get rid of `?` below. |
+ return packages?.resolve(uri, notFound: (_) => null); |
ahe
2017/07/14 13:44:57
Handle not found by reporting an error?
Siggi Cherem (dart-lang)
2017/07/14 19:54:06
Done.
Note I was preserving the old semantics her
|
+ } on ArgumentError catch (_) { |
ahe
2017/07/14 13:44:58
Argument error can occur for many reasons. Why is
Siggi Cherem (dart-lang)
2017/07/14 19:54:06
I hear you. As discussed offline, I filed a bug on
|
+ // TODO(sigmund): report an error. |
Siggi Cherem (dart-lang)
2017/07/14 04:58:52
(I plan to do so once Peter lands his CL adding co
|
+ return null; |
+ } |
} |
static Future<UriTranslator> parse(FileSystem fileSystem, Uri sdk, |
@@ -111,9 +114,9 @@ class UriTranslatorImpl implements UriTranslator { |
deprecated_inputError(packages, -1, e.message); |
} |
- Map<String, Uri> parsedPackages; |
+ Packages parsedPackages; |
try { |
- parsedPackages = packages_file.parse(bytes, packages); |
+ parsedPackages = new MapPackages(packages_file.parse(bytes, packages)); |
} on FormatException catch (e) { |
return deprecated_inputError(packages, e.offset, e.message); |
} |