Skip to content

Commit c0491ef

Browse files
authored
Fix templates in one liners (#2383)
* Add a basic test * Fix test so it actually reproduces the problem * Fix weird wheretype
1 parent afa4199 commit c0491ef

File tree

5 files changed

+39
-5
lines changed

5 files changed

+39
-5
lines changed

lib/src/model/package_graph.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,20 @@ class PackageGraph {
125125

126126
for (var m in allModelElements) {
127127
// Skip if there is a canonicalModelElement somewhere else we can run this
128-
// for. Not the same as allCanonicalModelElements since we need to run
128+
// for and we won't need a one line document that is precached.
129+
// Not the same as allCanonicalModelElements since we need to run
129130
// for any ModelElement that might not have a canonical ModelElement,
130131
// too.
131-
if (m.canonicalModelElement != null && !m.isCanonical) continue;
132+
if (m.canonicalModelElement !=
133+
null // A canonical element exists somewhere
134+
&&
135+
!m.isCanonical // This element is not canonical
136+
&&
137+
!m.enclosingElement
138+
.isCanonical // The enclosingElement won't need a oneLineDoc from this
139+
) {
140+
continue;
141+
}
132142
yield* precacheOneElement(m);
133143
}
134144
}

test/end2end/model_test.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ void main() {
610610
});
611611

612612
group('Macros', () {
613-
Class dog;
613+
Class dog, ClassTemplateOneLiner;
614614
Enum MacrosFromAccessors;
615615
Method withMacro, withMacro2, withPrivateMacro, withUndefinedMacro;
616616
EnumField macroReferencedHere;
@@ -628,6 +628,16 @@ void main() {
628628
fakeLibrary.enums.firstWhere((e) => e.name == 'MacrosFromAccessors');
629629
macroReferencedHere = MacrosFromAccessors.publicConstantFields
630630
.firstWhere((e) => e.name == 'macroReferencedHere');
631+
ClassTemplateOneLiner = exLibrary.allClasses
632+
.firstWhere((c) => c.name == 'ClassTemplateOneLiner');
633+
});
634+
635+
test('via reexport does not leave behind template crumbs', () {
636+
expect(ClassTemplateOneLiner.isCanonical, isFalse);
637+
expect(
638+
ClassTemplateOneLiner.oneLineDoc,
639+
equals(
640+
'I had better not have a template directive in my one liner.'));
631641
});
632642

633643
test('renders a macro defined within a enum', () {
@@ -1503,7 +1513,7 @@ void main() {
15031513
});
15041514

15051515
test('correctly finds all the classes', () {
1506-
expect(classes, hasLength(36));
1516+
expect(classes, hasLength(37));
15071517
});
15081518

15091519
test('abstract', () {

testing/test_package/lib/example.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import 'package:test_package_imported/main.dart';
1111
export 'dart:core' show deprecated, Deprecated;
1212
import 'package:meta/meta.dart' show protected, factory;
1313

14-
export 'fake.dart' show Cool;
14+
export 'fake.dart' show Cool, ClassTemplateOneLiner;
1515
export 'src/mylib.dart' show Helper;
1616

1717
const String COLOR = 'red';

testing/test_package/lib/fake.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ export 'src/tool.dart';
7373
// ignore: uri_does_not_exist
7474
export 'package:test_package/fake.dart';
7575

76+
export 'src/reexport_this.dart';
77+
7678
/// Does not render with emoji 3ffe:2a00:100:7031::1
7779
const int hasMarkdownInDoc = 1;
7880

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
library reexport_this;
3+
4+
/// {@template example:templateMemberTest}
5+
/// I had better not have a template directive in my one liner.
6+
///
7+
/// Even if it has links to [Dog] or other classes.
8+
///
9+
/// And if I do, a test should fail.
10+
/// {@endtemplate}
11+
class ClassTemplateOneLiner {
12+
}

0 commit comments

Comments
 (0)