Skip to content

Commit e4cdbd6

Browse files
authored
Record rendering simplification (#3344)
1 parent dba6f94 commit e4cdbd6

File tree

3 files changed

+15
-25
lines changed

3 files changed

+15
-25
lines changed

lib/src/render/element_type_renderer.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ class RecordElementTypeRendererHtml
123123
@override
124124
String renderLinkedName(RecordElementType elementType) {
125125
var buffer = StringBuffer()
126-
..write(elementType.nameWithGenerics)
127126
..write('(')
128127
..write(const RecordTypeFieldListHtmlRenderer()
129128
.renderLinkedFields(elementType)

lib/src/render/record_type_field_renderer.dart

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,12 @@ abstract class _RecordTypeFieldListRenderer {
8686
var linkedTypeName = typeName(modelType.linkedName);
8787
if (linkedTypeName.isNotEmpty) {
8888
fieldBuffer.write(linkedTypeName);
89+
}
90+
if (field is RecordTypeNamedField) {
8991
fieldBuffer.write(' ');
92+
fieldBuffer.write(fieldName(field.name));
9093
}
91-
var name = field is RecordTypeNamedField
92-
? field.name
93-
: _fieldName(field, index);
94-
fieldBuffer.write(fieldName(name));
9594
fieldBuffer.write(suffix);
96-
9795
buffer.write(listItem(this.field(fieldBuffer.toString())));
9896
});
9997
}
@@ -114,6 +112,4 @@ abstract class _RecordTypeFieldListRenderer {
114112
}
115113
return orderedList(buffer.toString());
116114
}
117-
118-
String _fieldName(RecordTypeField field, int index) => '\$$index';
119115
}

test/record_test.dart

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,33 @@ class RecordTest extends DartdocTestBase {
2222
String get libraryName => 'records';
2323

2424
@override
25-
String get sdkConstraint => '>=2.19.0-0 <3.0.0';
25+
String get sdkConstraint => '>=2.19.0-0 <4.0.0';
2626

2727
@override
2828
List<String> get experiments => ['records'];
2929

3030
void test_noFields() async {
3131
var library = await bootPackageWithLibrary('''
32-
void f(() record) {}
32+
void f(() r) {}
3333
''');
3434
var fFunction = library.functions.named('f');
3535
var recordType = fFunction.modelType.parameters.first.modelType;
36-
expect(recordType.linkedName, equals('Record()'));
36+
expect(recordType.linkedName, equals('()'));
3737
expect(recordType.nameWithGenerics, equals('Record'));
3838
}
3939

4040
void test_onePositionalField() async {
4141
var library = await bootPackageWithLibrary('''
42-
void f((int) record) {}
42+
void f((int) r) {}
4343
''');
4444
var fFunction = library.functions.named('f');
4545
var recordType = fFunction.modelType.parameters.first.modelType;
4646
expect(recordType.linkedName, matchesCompressed(r'''
47-
Record\(
47+
\(
4848
<span class="field">
4949
<span class="type-annotation">
5050
<a href=".*/dart-core/int-class.html">int</a>
5151
</span>
52-
<span class="field-name">\$0</span>
5352
</span>
5453
\)
5554
'''));
@@ -58,23 +57,21 @@ void f((int) record) {}
5857

5958
void test_positionalFields() async {
6059
var library = await bootPackageWithLibrary('''
61-
void f((int, String) record) {}
60+
void f((int, String) r) {}
6261
''');
6362
var fFunction = library.functions.named('f');
6463
var recordType = fFunction.modelType.parameters.first.modelType;
6564
expect(recordType.linkedName, matchesCompressed(r'''
66-
Record\(
65+
\(
6766
<span class="field">
6867
<span class="type-annotation">
6968
<a href=".*/dart-core/int-class.html">int</a>
70-
</span>
71-
<span class="field-name">\$0</span>,
69+
</span>,
7270
</span>
7371
<span class="field">
7472
<span class="type-annotation">
7573
<a href=".*/dart-core/String-class.html">String</a>
7674
</span>
77-
<span class="field-name">\$1</span>
7875
</span>
7976
\)
8077
'''));
@@ -88,7 +85,7 @@ void f(({int bbb, String aaa}) record) {}
8885
var fFunction = library.functions.named('f');
8986
var recordType = fFunction.modelType.parameters.first.modelType;
9087
expect(recordType.linkedName, matchesCompressed(r'''
91-
Record\(
88+
\(
9289
<span class="field">
9390
\{
9491
<span class="type-annotation">
@@ -115,18 +112,16 @@ void f((int one, String two, {int ccc, String aaa, int bbb}) record) {}
115112
var fFunction = library.functions.named('f');
116113
var recordType = fFunction.modelType.parameters.first.modelType;
117114
expect(recordType.linkedName, matchesCompressed(r'''
118-
Record\(
115+
\(
119116
<span class="field">
120117
<span class="type-annotation">
121118
<a href=".*/dart-core/int-class.html">int</a>
122-
</span>
123-
<span class="field-name">\$0</span>,
119+
</span>,
124120
</span>
125121
<span class="field">
126122
<span class="type-annotation">
127123
<a href=".*/dart-core/String-class.html">String</a>
128-
</span>
129-
<span class="field-name">\$1</span>,
124+
</span>,
130125
</span>
131126
<span class="field">
132127
\{

0 commit comments

Comments
 (0)