Skip to content

Commit 4fe6b1d

Browse files
authored
Migrate runtime renderer to NNBD (#2849)
* squash from chain merges * Things seem to work now, if not completely cleanly. * Get runtime_renderer_render_test ready for NNBD strong mode, fix a few more problems * deconfuse github * add todo
1 parent b81bcce commit 4fe6b1d

7 files changed

+2748
-1932
lines changed

lib/src/generator/templates.runtime_renderers.dart

Lines changed: 2542 additions & 1752 deletions
Large diffs are not rendered by default.

lib/src/mustachio/renderer_base.dart

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,9 @@ abstract class RendererBase<T extends Object?> {
269269

270270
// If this section is not a conditional or repeated section, it is a value
271271
// section, regardless of type.
272-
var isNullValue = property.isNullValue!;
273-
if (node.invert && isNullValue(context)) {
272+
if (node.invert && property.isNullValue(context)) {
274273
renderBlock(node.children);
275-
} else if (!node.invert && !isNullValue(context)) {
274+
} else if (!node.invert && !property.isNullValue(context)) {
276275
property.renderValue!(context, this, node.children, sink);
277276
}
278277
}
@@ -288,17 +287,17 @@ abstract class RendererBase<T extends Object?> {
288287
}
289288
}
290289

291-
String renderSimple(
292-
Object context, List<MustachioNode> ast, Template template, StringSink sink,
290+
String renderSimple(Object? context, List<MustachioNode> ast, Template template,
291+
StringSink sink,
293292
{required RendererBase<Object> parent, required Set<String> getters}) {
294293
var renderer = SimpleRenderer(context, parent, template, sink, getters);
295294
renderer.renderBlock(ast);
296295
return renderer.sink.toString();
297296
}
298297

299-
class SimpleRenderer extends RendererBase<Object> {
298+
class SimpleRenderer extends RendererBase<Object?> {
300299
SimpleRenderer(
301-
Object context,
300+
Object? context,
302301
RendererBase<Object> parent,
303302
Template template,
304303
StringSink sink,
@@ -356,7 +355,7 @@ class Property<T> {
356355
final Iterable<void> Function(
357356
T, RendererBase<T>, List<MustachioNode>, StringSink)? renderIterable;
358357

359-
final bool Function(T)? isNullValue;
358+
final bool Function(T) isNullValue;
360359

361360
final void Function(T, RendererBase<T>, List<MustachioNode>, StringSink)?
362361
renderValue;
@@ -366,8 +365,11 @@ class Property<T> {
366365
required this.renderVariable,
367366
this.getBool,
368367
this.renderIterable,
369-
this.isNullValue,
370-
this.renderValue});
368+
// TODO(jcollins-g): consider making this required or emitting warnings
369+
// if called on a non-nullable?
370+
bool Function(T)? isNullValue,
371+
this.renderValue})
372+
: isNullValue = (isNullValue ?? (_) => false);
371373

372374
String renderSimpleVariable(
373375
T c, List<String> remainingNames, String typeString) {

test/mustachio/foo.dart

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// @dart=2.9
2-
31
@Renderer.forTest(#renderFoo, Context<Foo>(), 'foo',
42
visibleTypes: {Property1, Property2, Property3})
53
@Renderer.forTest(#renderBar, Context<Bar>(), 'bar')
@@ -9,43 +7,43 @@ library dartdoc.testing.foo;
97
import 'package:dartdoc/src/mustachio/annotations.dart';
108

119
class FooBase<T extends Object> {
12-
T baz;
10+
T? baz;
1311
}
1412

1513
class Foo extends FooBase<Baz> {
16-
String s1;
17-
bool b1;
18-
List<int> l1;
14+
String s1 = '';
15+
bool b1 = false;
16+
List<int> l1 = [];
1917
@override
2018
// ignore: overridden_fields
21-
Baz baz;
22-
Property1 p1;
23-
int length;
19+
Baz? baz;
20+
Property1? p1;
21+
int? length;
2422
}
2523

2624
class Bar {
27-
Foo foo;
28-
String s2;
29-
Baz baz;
30-
bool l1;
25+
Foo? foo;
26+
String? s2;
27+
Baz? baz;
28+
bool? l1;
3129
}
3230

3331
class Baz {
34-
Bar bar;
32+
Bar? bar;
3533
}
3634

3735
class Property1 {
38-
Property2 p2;
36+
Property2? p2;
3937
}
4038

4139
class Property2 with Mixin1 {
42-
String s;
40+
String? s;
4341
}
4442

4543
mixin Mixin1 {
46-
Property3 p3;
44+
Property3? p3;
4745
}
4846

4947
class Property3 {
50-
String s;
48+
String? s;
5149
}

0 commit comments

Comments
 (0)