Skip to content

Migrate runtime renderer to NNBD #2849

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
4,294 changes: 2,542 additions & 1,752 deletions lib/src/generator/templates.runtime_renderers.dart

Large diffs are not rendered by default.

22 changes: 12 additions & 10 deletions lib/src/mustachio/renderer_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,9 @@ abstract class RendererBase<T extends Object?> {

// If this section is not a conditional or repeated section, it is a value
// section, regardless of type.
var isNullValue = property.isNullValue!;
if (node.invert && isNullValue(context)) {
if (node.invert && property.isNullValue(context)) {
renderBlock(node.children);
} else if (!node.invert && !isNullValue(context)) {
} else if (!node.invert && !property.isNullValue(context)) {
property.renderValue!(context, this, node.children, sink);
}
}
Expand All @@ -288,17 +287,17 @@ abstract class RendererBase<T extends Object?> {
}
}

String renderSimple(
Object context, List<MustachioNode> ast, Template template, StringSink sink,
String renderSimple(Object? context, List<MustachioNode> ast, Template template,
StringSink sink,
{required RendererBase<Object> parent, required Set<String> getters}) {
var renderer = SimpleRenderer(context, parent, template, sink, getters);
renderer.renderBlock(ast);
return renderer.sink.toString();
}

class SimpleRenderer extends RendererBase<Object> {
class SimpleRenderer extends RendererBase<Object?> {
SimpleRenderer(
Object context,
Object? context,
RendererBase<Object> parent,
Template template,
StringSink sink,
Expand Down Expand Up @@ -356,7 +355,7 @@ class Property<T> {
final Iterable<void> Function(
T, RendererBase<T>, List<MustachioNode>, StringSink)? renderIterable;

final bool Function(T)? isNullValue;
final bool Function(T) isNullValue;

final void Function(T, RendererBase<T>, List<MustachioNode>, StringSink)?
renderValue;
Expand All @@ -366,8 +365,11 @@ class Property<T> {
required this.renderVariable,
this.getBool,
this.renderIterable,
this.isNullValue,
this.renderValue});
// TODO(jcollins-g): consider making this required or emitting warnings
// if called on a non-nullable?
bool Function(T)? isNullValue,
this.renderValue})
: isNullValue = (isNullValue ?? (_) => false);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is mostly food for NNBD, as we will pass this in wherever it is used? Maybe it should be required?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a bad idea. I think fine to leave a TODO and refactor later.


String renderSimpleVariable(
T c, List<String> remainingNames, String typeString) {
Expand Down
34 changes: 16 additions & 18 deletions test/mustachio/foo.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @dart=2.9

@Renderer.forTest(#renderFoo, Context<Foo>(), 'foo',
visibleTypes: {Property1, Property2, Property3})
@Renderer.forTest(#renderBar, Context<Bar>(), 'bar')
Expand All @@ -9,43 +7,43 @@ library dartdoc.testing.foo;
import 'package:dartdoc/src/mustachio/annotations.dart';

class FooBase<T extends Object> {
T baz;
T? baz;
}

class Foo extends FooBase<Baz> {
String s1;
bool b1;
List<int> l1;
String s1 = '';
bool b1 = false;
List<int> l1 = [];
@override
// ignore: overridden_fields
Baz baz;
Property1 p1;
int length;
Baz? baz;
Property1? p1;
int? length;
}

class Bar {
Foo foo;
String s2;
Baz baz;
bool l1;
Foo? foo;
String? s2;
Baz? baz;
bool? l1;
}

class Baz {
Bar bar;
Bar? bar;
}

class Property1 {
Property2 p2;
Property2? p2;
}

class Property2 with Mixin1 {
String s;
String? s;
}

mixin Mixin1 {
Property3 p3;
Property3? p3;
}

class Property3 {
String s;
String? s;
}
Loading