Skip to content

Commit 10700c7

Browse files
committed
Correct the wildcard tests for import prefixes.
An unrelated fix, #3865, revealed that the wildcard-variables experiment was not actually enabled in tests; the SDK constraint used in test packages needs to be '^3.6.0'. With that fix, there are some questions about how much dartdoc should be doing to keep wildcards "non-binding" and how much the analyzer should be doing. So that is raised in #3769 (comment).
1 parent 46564a6 commit 10700c7

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

lib/src/model/comment_referable.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ library;
77

88
import 'dart:core';
99

10+
import 'package:analyzer/dart/analysis/features.dart';
1011
import 'package:analyzer/dart/element/element.dart';
1112
import 'package:analyzer/dart/element/scope.dart';
1213
import 'package:collection/collection.dart';
1314
import 'package:dartdoc/src/model/library.dart';
1415
import 'package:dartdoc/src/model/model_element.dart';
1516
import 'package:dartdoc/src/model/nameable.dart';
17+
import 'package:dartdoc/src/model/prefix.dart';
1618
import 'package:meta/meta.dart';
1719

1820
class _ReferenceChildrenLookup {
@@ -55,6 +57,12 @@ mixin CommentReferable implements Nameable {
5557
// First attempt: Ask analyzer's `Scope.lookup` API.
5658
var result = _lookupViaScope(referenceLookup, filter: filter);
5759
if (result != null) {
60+
if (result is Prefix &&
61+
result.name == '_' &&
62+
library!.element.featureSet.isEnabled(Feature.wildcard_variables)) {
63+
// A wildcard import prefix is non-binding.
64+
continue;
65+
}
5866
return result;
5967
}
6068

lib/src/model/library.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'package:analyzer/dart/analysis/features.dart';
56
import 'package:analyzer/dart/element/element.dart';
67
import 'package:analyzer/dart/element/scope.dart';
78
import 'package:analyzer/source/line_info.dart';
@@ -442,6 +443,11 @@ class Library extends ModelElement
442443
// ambiguous. dart-lang/dartdoc#2683.
443444
for (var MapEntry(key: prefix, value: libraries)
444445
in _prefixToLibrary.entries) {
446+
if (prefix == '_' &&
447+
element.featureSet.isEnabled(Feature.wildcard_variables)) {
448+
// A wildcard import prefix is non-binding.
449+
continue;
450+
}
445451
referenceChildrenBuilder.putIfAbsent(prefix, () => libraries.first);
446452
}
447453
return referenceChildrenBuilder;

test/dartdoc_test_base.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,12 @@ abstract class DartdocTestBase {
3636

3737
String get linkPrefix => '$placeholder$libraryName';
3838

39+
String get dartAsyncUrlPrefix =>
40+
'https://api.dart.dev/stable/3.2.0/dart-async';
41+
3942
String get dartCoreUrlPrefix => 'https://api.dart.dev/stable/3.2.0/dart-core';
4043

41-
String get sdkConstraint => '>=3.3.0 <4.0.0';
44+
String get sdkConstraint => '>=3.6.0 <4.0.0';
4245

4346
List<String> get experiments => ['wildcard-variables'];
4447

test/prefixes_test.dart

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class PrefixesTest extends DartdocTestBase {
1919
@override
2020
String get libraryName => 'prefixes';
2121

22+
@FailingTest(
23+
reason: 'requires https://github.com/dart-lang/dartdoc/pull/3865')
2224
void test_referenced() async {
2325
var library = await bootPackageWithLibrary(
2426
'''
@@ -29,9 +31,11 @@ int x = 0;
2931
''',
3032
additionalArguments: ['--link-to-remote'],
3133
);
32-
var f = library.properties.named('x');
33-
// There is no link, but also no wrong link or crash.
34-
expect(f.documentationAsHtml, '<p>Text <code>async</code>.</p>');
34+
var x = library.properties.named('x');
35+
expect(
36+
x.documentationAsHtml,
37+
'<p>Text <a href="$dartAsyncUrlPrefix/dart-async-library.html">async</a>.</p>',
38+
);
3539
}
3640

3741
void test_referenced_wildcard() async {
@@ -44,8 +48,8 @@ int x = 0;
4448
''',
4549
additionalArguments: ['--link-to-remote'],
4650
);
47-
var f = library.properties.named('x');
51+
var x = library.properties.named('x');
4852
// There is no link, but also no wrong link or crash.
49-
expect(f.documentationAsHtml, '<p>Text <code>_</code>.</p>');
53+
expect(x.documentationAsHtml, '<p>Text <code>_</code>.</p>');
5054
}
5155
}

0 commit comments

Comments
 (0)