Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/src/model/comment_referable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ library;

import 'dart:core';

import 'package:analyzer/dart/analysis/features.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/scope.dart';
import 'package:collection/collection.dart';
import 'package:dartdoc/src/model/library.dart';
import 'package:dartdoc/src/model/model_element.dart';
import 'package:dartdoc/src/model/nameable.dart';
import 'package:dartdoc/src/model/prefix.dart';
import 'package:meta/meta.dart';

class _ReferenceChildrenLookup {
Expand Down Expand Up @@ -55,6 +57,12 @@ mixin CommentReferable implements Nameable {
// First attempt: Ask analyzer's `Scope.lookup` API.
var result = _lookupViaScope(referenceLookup, filter: filter);
if (result != null) {
if (result is Prefix &&
result.name == '_' &&
library!.element.featureSet.isEnabled(Feature.wildcard_variables)) {
// A wildcard import prefix is non-binding.
continue;
}
return result;
}

Expand Down
6 changes: 6 additions & 0 deletions lib/src/model/library.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:analyzer/dart/analysis/features.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/scope.dart';
import 'package:analyzer/source/line_info.dart';
Expand Down Expand Up @@ -442,6 +443,11 @@ class Library extends ModelElement
// ambiguous. dart-lang/dartdoc#2683.
for (var MapEntry(key: prefix, value: libraries)
in _prefixToLibrary.entries) {
if (prefix == '_' &&
element.featureSet.isEnabled(Feature.wildcard_variables)) {
// A wildcard import prefix is non-binding.
continue;
}
referenceChildrenBuilder.putIfAbsent(prefix, () => libraries.first);
}
return referenceChildrenBuilder;
Expand Down
5 changes: 4 additions & 1 deletion test/dartdoc_test_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ abstract class DartdocTestBase {

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

String get dartAsyncUrlPrefix =>
'https://api.dart.dev/stable/3.2.0/dart-async';

String get dartCoreUrlPrefix => 'https://api.dart.dev/stable/3.2.0/dart-core';

String get sdkConstraint => '>=3.3.0 <4.0.0';
String get sdkConstraint => '>=3.6.0 <4.0.0';

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

Expand Down
14 changes: 9 additions & 5 deletions test/prefixes_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class PrefixesTest extends DartdocTestBase {
@override
String get libraryName => 'prefixes';

@FailingTest(
reason: 'requires https://github.com/dart-lang/dartdoc/pull/3865')
void test_referenced() async {
var library = await bootPackageWithLibrary(
'''
Expand All @@ -29,9 +31,11 @@ int x = 0;
''',
additionalArguments: ['--link-to-remote'],
);
var f = library.properties.named('x');
// There is no link, but also no wrong link or crash.
expect(f.documentationAsHtml, '<p>Text <code>async</code>.</p>');
var x = library.properties.named('x');
expect(
x.documentationAsHtml,
'<p>Text <a href="$dartAsyncUrlPrefix/dart-async-library.html">async</a>.</p>',
);
}

void test_referenced_wildcard() async {
Expand All @@ -44,8 +48,8 @@ int x = 0;
''',
additionalArguments: ['--link-to-remote'],
);
var f = library.properties.named('x');
var x = library.properties.named('x');
// There is no link, but also no wrong link or crash.
expect(f.documentationAsHtml, '<p>Text <code>_</code>.</p>');
expect(x.documentationAsHtml, '<p>Text <code>_</code>.</p>');
}
}