[kernel] Lookup import conditions against the core library's loader.

Change-Id: Ib16d9f33a40ee25aed2a86a29a74bbc2b301d2e4
Reviewed-on: https://dart-review.googlesource.com/34940
Reviewed-by: Samir Jindel <sjindel@google.com>
Commit-Queue: Samir Jindel <sjindel@google.com>
This commit is contained in:
Samir Jindel 2018-01-16 23:21:42 +00:00 committed by commit-bot@chromium.org
parent 6b3576f673
commit ce1294fe3d
3 changed files with 15 additions and 9 deletions

View file

@ -202,6 +202,18 @@ abstract class SourceLibraryBuilder<T extends TypeBuilder, R>
exports.add(new Export(this, exportedLibrary, combinators, charOffset));
}
String _lookupImportCondition(String dottedName) {
const String prefix = "dart.library.";
if (!dottedName.startsWith(prefix)) return "";
dottedName = dottedName.substring(prefix.length);
LibraryBuilder coreLibrary =
loader.read(resolve(this.uri, "dart:core", -1), -1);
LibraryBuilder imported = coreLibrary
.loader.builders[new Uri(scheme: 'dart', path: dottedName)];
return imported != null ? "true" : "";
}
void addImport(
List<MetadataBuilder> metadata,
String uri,
@ -214,9 +226,7 @@ abstract class SourceLibraryBuilder<T extends TypeBuilder, R>
int uriOffset) {
if (configurations != null) {
for (Configuration config in configurations) {
if (loader.target.backendTarget
.lookupImportCondition(config.dottedName) ==
config.condition) {
if (_lookupImportCondition(config.dottedName) == config.condition) {
uri = config.importUri;
break;
}

View file

@ -152,10 +152,6 @@ abstract class Target {
/// extensions, but targets like dart2js only enable it on the core libraries.
bool enableNative(Uri uri) => false;
/// Returns whether the given condition Uri should evaluate to true for the
/// purposes of resolving conditional imports.
String lookupImportCondition(String condition) => "";
/// There are two variants of the `native` language extension. The VM expects
/// the native token to be followed by string, whereas dart2js and DDC do not.
// TODO(sigmund, ahe): ideally we should remove the `native` syntax, if not,

View file

@ -714,8 +714,8 @@ truncdiv_test: RuntimeError # Issue 29920
[ $compiler == dartdevk && $runtime != none ]
callable_test/none: RuntimeError # Expect.throws(TypeError) fails: Did not throw
conditional_import_string_test: RuntimeError # Unsupported operation: String.fromEnvironment can only be used as a const constructor
conditional_import_test: RuntimeError # Unsupported operation: bool.fromEnvironment can only be used as a const constructor
conditional_import_string_test: CompileTimeError # Test is broken
conditional_import_test: CompileTimeError # Test is broken
cyclic_type_test/00: RuntimeError # Expect.equals(expected: <Derived>, actual: <dynamic>) fails.
cyclic_type_test/01: RuntimeError # Expect.equals(at index 0: Expected <Derived<Derived<int>>...>, Found: <dynamic>) fails.
enum_duplicate_test/01: RuntimeError # NoSuchMethodError: method not found: '<Unexpected Null Value>'