Fix selecting URI for import/export configuration with '== true'.

R=brianwilkerson@google.com

Change-Id: Ie18d5f76041342c6a42fd7b1f8a3be55a6e8adee
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/112302
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov 2019-08-08 18:24:44 +00:00 committed by commit-bot@chromium.org
parent f6592223ae
commit 559f7cd182
2 changed files with 118 additions and 12 deletions

View file

@ -307,8 +307,8 @@ class SourceLibraryBuilder {
) {
for (var configuration in configurations) {
var name = configuration.name.components.join('.');
var value = configuration.value ?? 'true';
if (linker.declaredVariables.get(name) == (value)) {
var value = configuration.value?.stringValue ?? 'true';
if (linker.declaredVariables.get(name) == value) {
return configuration.uri.stringValue;
}
}

View file

@ -5826,8 +5826,9 @@ Exports:
}
test_export_configurations_useDefault() async {
declaredVariables =
new DeclaredVariables.fromMap({'dart.library.io': 'false'});
declaredVariables = new DeclaredVariables.fromMap({
'dart.library.io': 'false',
});
addLibrarySource('/foo.dart', 'class A {}');
addLibrarySource('/foo_io.dart', 'class A {}');
addLibrarySource('/foo_html.dart', 'class A {}');
@ -5850,8 +5851,10 @@ Exports:
}
test_export_configurations_useFirst() async {
declaredVariables = new DeclaredVariables.fromMap(
{'dart.library.io': 'true', 'dart.library.html': 'true'});
declaredVariables = new DeclaredVariables.fromMap({
'dart.library.io': 'true',
'dart.library.html': 'true',
});
addLibrarySource('/foo.dart', 'class A {}');
addLibrarySource('/foo_io.dart', 'class A {}');
addLibrarySource('/foo_html.dart', 'class A {}');
@ -5874,8 +5877,10 @@ Exports:
}
test_export_configurations_useSecond() async {
declaredVariables = new DeclaredVariables.fromMap(
{'dart.library.io': 'false', 'dart.library.html': 'true'});
declaredVariables = new DeclaredVariables.fromMap({
'dart.library.io': 'false',
'dart.library.html': 'true',
});
addLibrarySource('/foo.dart', 'class A {}');
addLibrarySource('/foo_io.dart', 'class A {}');
addLibrarySource('/foo_html.dart', 'class A {}');
@ -6079,8 +6084,9 @@ Exports:
}
test_exportImport_configurations_useDefault() async {
declaredVariables =
new DeclaredVariables.fromMap({'dart.library.io': 'false'});
declaredVariables = new DeclaredVariables.fromMap({
'dart.library.io': 'false',
});
addLibrarySource('/foo.dart', 'class A {}');
addLibrarySource('/foo_io.dart', 'class A {}');
addLibrarySource('/foo_html.dart', 'class A {}');
@ -6103,8 +6109,10 @@ class B extends A {
}
test_exportImport_configurations_useFirst() async {
declaredVariables = new DeclaredVariables.fromMap(
{'dart.library.io': 'true', 'dart.library.html': 'true'});
declaredVariables = new DeclaredVariables.fromMap({
'dart.library.io': 'true',
'dart.library.html': 'false',
});
addLibrarySource('/foo.dart', 'class A {}');
addLibrarySource('/foo_io.dart', 'class A {}');
addLibrarySource('/foo_html.dart', 'class A {}');
@ -6126,6 +6134,32 @@ class B extends A {
expect(typeA.element.source.shortName, 'foo_io.dart');
}
test_exportImport_configurations_useSecond() async {
declaredVariables = new DeclaredVariables.fromMap({
'dart.library.io': 'false',
'dart.library.html': 'true',
});
addLibrarySource('/foo.dart', 'class A {}');
addLibrarySource('/foo_io.dart', 'class A {}');
addLibrarySource('/foo_html.dart', 'class A {}');
addLibrarySource('/bar.dart', r'''
export 'foo.dart'
if (dart.library.io) 'foo_io.dart'
if (dart.library.html) 'foo_html.dart';
''');
var library = await checkLibrary(r'''
import 'bar.dart';
class B extends A {}
''');
checkElementText(library, r'''
import 'bar.dart';
class B extends A {
}
''');
var typeA = library.definingCompilationUnit.getType('B').supertype;
expect(typeA.element.source.shortName, 'foo_html.dart');
}
test_exports() async {
addLibrarySource('/a.dart', 'library a;');
addLibrarySource('/b.dart', 'library b;');
@ -6958,6 +6992,78 @@ class B extends A {
expect(typeA.element.source.shortName, 'foo_io.dart');
}
test_import_configurations_useFirst_eqTrue() async {
declaredVariables = new DeclaredVariables.fromMap({
'dart.library.io': 'true',
'dart.library.html': 'true',
});
addLibrarySource('/foo.dart', 'class A {}');
addLibrarySource('/foo_io.dart', 'class A {}');
addLibrarySource('/foo_html.dart', 'class A {}');
var library = await checkLibrary(r'''
import 'foo.dart'
if (dart.library.io == 'true') 'foo_io.dart'
if (dart.library.html == 'true') 'foo_html.dart';
class B extends A {}
''');
checkElementText(library, r'''
import 'foo_io.dart';
class B extends A {
}
''');
var typeA = library.definingCompilationUnit.getType('B').supertype;
expect(typeA.element.source.shortName, 'foo_io.dart');
}
test_import_configurations_useSecond() async {
declaredVariables = new DeclaredVariables.fromMap({
'dart.library.io': 'false',
'dart.library.html': 'true',
});
addLibrarySource('/foo.dart', 'class A {}');
addLibrarySource('/foo_io.dart', 'class A {}');
addLibrarySource('/foo_html.dart', 'class A {}');
var library = await checkLibrary(r'''
import 'foo.dart'
if (dart.library.io) 'foo_io.dart'
if (dart.library.html) 'foo_html.dart';
class B extends A {}
''');
checkElementText(library, r'''
import 'foo_html.dart';
class B extends A {
}
''');
var typeA = library.definingCompilationUnit.getType('B').supertype;
expect(typeA.element.source.shortName, 'foo_html.dart');
}
test_import_configurations_useSecond_eqTrue() async {
declaredVariables = new DeclaredVariables.fromMap({
'dart.library.io': 'false',
'dart.library.html': 'true',
});
addLibrarySource('/foo.dart', 'class A {}');
addLibrarySource('/foo_io.dart', 'class A {}');
addLibrarySource('/foo_html.dart', 'class A {}');
var library = await checkLibrary(r'''
import 'foo.dart'
if (dart.library.io == 'true') 'foo_io.dart'
if (dart.library.html == 'true') 'foo_html.dart';
class B extends A {}
''');
checkElementText(library, r'''
import 'foo_html.dart';
class B extends A {
}
''');
var typeA = library.definingCompilationUnit.getType('B').supertype;
expect(typeA.element.source.shortName, 'foo_html.dart');
}
test_import_deferred() async {
addLibrarySource('/a.dart', 'f() {}');
var library = await checkLibrary('''