Skip to content

Commit 559f7cd

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Fix selecting URI for import/export configuration with '== true'.
[email protected] Change-Id: Ie18d5f76041342c6a42fd7b1f8a3be55a6e8adee Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/112302 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent f659222 commit 559f7cd

File tree

2 files changed

+118
-12
lines changed

2 files changed

+118
-12
lines changed

pkg/analyzer/lib/src/summary2/builder/source_library_builder.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,8 @@ class SourceLibraryBuilder {
307307
) {
308308
for (var configuration in configurations) {
309309
var name = configuration.name.components.join('.');
310-
var value = configuration.value ?? 'true';
311-
if (linker.declaredVariables.get(name) == (value)) {
310+
var value = configuration.value?.stringValue ?? 'true';
311+
if (linker.declaredVariables.get(name) == value) {
312312
return configuration.uri.stringValue;
313313
}
314314
}

pkg/analyzer/test/src/summary/resynthesize_common.dart

Lines changed: 116 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5826,8 +5826,9 @@ Exports:
58265826
}
58275827

58285828
test_export_configurations_useDefault() async {
5829-
declaredVariables =
5830-
new DeclaredVariables.fromMap({'dart.library.io': 'false'});
5829+
declaredVariables = new DeclaredVariables.fromMap({
5830+
'dart.library.io': 'false',
5831+
});
58315832
addLibrarySource('/foo.dart', 'class A {}');
58325833
addLibrarySource('/foo_io.dart', 'class A {}');
58335834
addLibrarySource('/foo_html.dart', 'class A {}');
@@ -5850,8 +5851,10 @@ Exports:
58505851
}
58515852

58525853
test_export_configurations_useFirst() async {
5853-
declaredVariables = new DeclaredVariables.fromMap(
5854-
{'dart.library.io': 'true', 'dart.library.html': 'true'});
5854+
declaredVariables = new DeclaredVariables.fromMap({
5855+
'dart.library.io': 'true',
5856+
'dart.library.html': 'true',
5857+
});
58555858
addLibrarySource('/foo.dart', 'class A {}');
58565859
addLibrarySource('/foo_io.dart', 'class A {}');
58575860
addLibrarySource('/foo_html.dart', 'class A {}');
@@ -5874,8 +5877,10 @@ Exports:
58745877
}
58755878

58765879
test_export_configurations_useSecond() async {
5877-
declaredVariables = new DeclaredVariables.fromMap(
5878-
{'dart.library.io': 'false', 'dart.library.html': 'true'});
5880+
declaredVariables = new DeclaredVariables.fromMap({
5881+
'dart.library.io': 'false',
5882+
'dart.library.html': 'true',
5883+
});
58795884
addLibrarySource('/foo.dart', 'class A {}');
58805885
addLibrarySource('/foo_io.dart', 'class A {}');
58815886
addLibrarySource('/foo_html.dart', 'class A {}');
@@ -6079,8 +6084,9 @@ Exports:
60796084
}
60806085

60816086
test_exportImport_configurations_useDefault() async {
6082-
declaredVariables =
6083-
new DeclaredVariables.fromMap({'dart.library.io': 'false'});
6087+
declaredVariables = new DeclaredVariables.fromMap({
6088+
'dart.library.io': 'false',
6089+
});
60846090
addLibrarySource('/foo.dart', 'class A {}');
60856091
addLibrarySource('/foo_io.dart', 'class A {}');
60866092
addLibrarySource('/foo_html.dart', 'class A {}');
@@ -6103,8 +6109,10 @@ class B extends A {
61036109
}
61046110

61056111
test_exportImport_configurations_useFirst() async {
6106-
declaredVariables = new DeclaredVariables.fromMap(
6107-
{'dart.library.io': 'true', 'dart.library.html': 'true'});
6112+
declaredVariables = new DeclaredVariables.fromMap({
6113+
'dart.library.io': 'true',
6114+
'dart.library.html': 'false',
6115+
});
61086116
addLibrarySource('/foo.dart', 'class A {}');
61096117
addLibrarySource('/foo_io.dart', 'class A {}');
61106118
addLibrarySource('/foo_html.dart', 'class A {}');
@@ -6126,6 +6134,32 @@ class B extends A {
61266134
expect(typeA.element.source.shortName, 'foo_io.dart');
61276135
}
61286136

6137+
test_exportImport_configurations_useSecond() async {
6138+
declaredVariables = new DeclaredVariables.fromMap({
6139+
'dart.library.io': 'false',
6140+
'dart.library.html': 'true',
6141+
});
6142+
addLibrarySource('/foo.dart', 'class A {}');
6143+
addLibrarySource('/foo_io.dart', 'class A {}');
6144+
addLibrarySource('/foo_html.dart', 'class A {}');
6145+
addLibrarySource('/bar.dart', r'''
6146+
export 'foo.dart'
6147+
if (dart.library.io) 'foo_io.dart'
6148+
if (dart.library.html) 'foo_html.dart';
6149+
''');
6150+
var library = await checkLibrary(r'''
6151+
import 'bar.dart';
6152+
class B extends A {}
6153+
''');
6154+
checkElementText(library, r'''
6155+
import 'bar.dart';
6156+
class B extends A {
6157+
}
6158+
''');
6159+
var typeA = library.definingCompilationUnit.getType('B').supertype;
6160+
expect(typeA.element.source.shortName, 'foo_html.dart');
6161+
}
6162+
61296163
test_exports() async {
61306164
addLibrarySource('/a.dart', 'library a;');
61316165
addLibrarySource('/b.dart', 'library b;');
@@ -6958,6 +6992,78 @@ class B extends A {
69586992
expect(typeA.element.source.shortName, 'foo_io.dart');
69596993
}
69606994

6995+
test_import_configurations_useFirst_eqTrue() async {
6996+
declaredVariables = new DeclaredVariables.fromMap({
6997+
'dart.library.io': 'true',
6998+
'dart.library.html': 'true',
6999+
});
7000+
addLibrarySource('/foo.dart', 'class A {}');
7001+
addLibrarySource('/foo_io.dart', 'class A {}');
7002+
addLibrarySource('/foo_html.dart', 'class A {}');
7003+
var library = await checkLibrary(r'''
7004+
import 'foo.dart'
7005+
if (dart.library.io == 'true') 'foo_io.dart'
7006+
if (dart.library.html == 'true') 'foo_html.dart';
7007+
7008+
class B extends A {}
7009+
''');
7010+
checkElementText(library, r'''
7011+
import 'foo_io.dart';
7012+
class B extends A {
7013+
}
7014+
''');
7015+
var typeA = library.definingCompilationUnit.getType('B').supertype;
7016+
expect(typeA.element.source.shortName, 'foo_io.dart');
7017+
}
7018+
7019+
test_import_configurations_useSecond() async {
7020+
declaredVariables = new DeclaredVariables.fromMap({
7021+
'dart.library.io': 'false',
7022+
'dart.library.html': 'true',
7023+
});
7024+
addLibrarySource('/foo.dart', 'class A {}');
7025+
addLibrarySource('/foo_io.dart', 'class A {}');
7026+
addLibrarySource('/foo_html.dart', 'class A {}');
7027+
var library = await checkLibrary(r'''
7028+
import 'foo.dart'
7029+
if (dart.library.io) 'foo_io.dart'
7030+
if (dart.library.html) 'foo_html.dart';
7031+
7032+
class B extends A {}
7033+
''');
7034+
checkElementText(library, r'''
7035+
import 'foo_html.dart';
7036+
class B extends A {
7037+
}
7038+
''');
7039+
var typeA = library.definingCompilationUnit.getType('B').supertype;
7040+
expect(typeA.element.source.shortName, 'foo_html.dart');
7041+
}
7042+
7043+
test_import_configurations_useSecond_eqTrue() async {
7044+
declaredVariables = new DeclaredVariables.fromMap({
7045+
'dart.library.io': 'false',
7046+
'dart.library.html': 'true',
7047+
});
7048+
addLibrarySource('/foo.dart', 'class A {}');
7049+
addLibrarySource('/foo_io.dart', 'class A {}');
7050+
addLibrarySource('/foo_html.dart', 'class A {}');
7051+
var library = await checkLibrary(r'''
7052+
import 'foo.dart'
7053+
if (dart.library.io == 'true') 'foo_io.dart'
7054+
if (dart.library.html == 'true') 'foo_html.dart';
7055+
7056+
class B extends A {}
7057+
''');
7058+
checkElementText(library, r'''
7059+
import 'foo_html.dart';
7060+
class B extends A {
7061+
}
7062+
''');
7063+
var typeA = library.definingCompilationUnit.getType('B').supertype;
7064+
expect(typeA.element.source.shortName, 'foo_html.dart');
7065+
}
7066+
69617067
test_import_deferred() async {
69627068
addLibrarySource('/a.dart', 'f() {}');
69637069
var library = await checkLibrary('''

0 commit comments

Comments
 (0)