Skip to content

Remove dependency on code_builder #3451

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 2 commits into from
Jun 22, 2023
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
777 changes: 463 additions & 314 deletions lib/src/generator/templates.aot_renderers_for_html.dart

Large diffs are not rendered by default.

682 changes: 403 additions & 279 deletions lib/src/generator/templates.aot_renderers_for_md.dart

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ dependencies:

dev_dependencies:
async: ^2.11.0
code_builder: ^4.4.0
dart_style: ^2.3.1
grinder: ^0.9.4
http: ">=0.13.6 <2.0.0"
Expand Down
17 changes: 7 additions & 10 deletions test/mustachio/aot_compiler_builder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ import 'annotations.dart';
],
);
var generatedContent = await File(aotRenderersForHtmlPath).readAsString();
expect(
generatedContent, contains('String renderFoo<T>(_i1.Foo<T> context0)'));
expect(generatedContent, contains('String renderFoo<T>(Foo<T> context0)'));
});

test('builds a private render function for a partial', () async {
Expand All @@ -94,10 +93,8 @@ import 'annotations.dart';
],
);
var generatedContent = await File(aotRenderersForHtmlPath).readAsString();
expect(
generatedContent,
contains(
'String _renderFoo_partial_foo_header_0<T>(_i1.Foo<T> context0)'));
expect(generatedContent,
contains('String _renderFoo_partial_foo_header_0<T>(Foo<T> context0)'));
});

test('builds a renderer for a generic, bounded type', () async {
Expand Down Expand Up @@ -151,12 +148,12 @@ import 'annotations.dart';
var generatedContent = await File(aotRenderersForHtmlPath).readAsString();
expect(
generatedContent,
contains('String _renderFoo_partial_base_0(_i1.Foo context0) =>\n'
contains('String _renderFoo_partial_base_0(Foo context0) =>\n'
' _deduplicated_lib_templates_html__base_html(context0);\n'),
);
expect(
generatedContent,
contains('String _renderBar_partial_base_0(_i1.Bar context0) =>\n'
contains('String _renderBar_partial_base_0(Bar context0) =>\n'
' _deduplicated_lib_templates_html__base_html(context0);\n'),
);
expect(
Expand Down Expand Up @@ -198,11 +195,11 @@ import 'annotations.dart';
var generatedContent = await File(aotRenderersForHtmlPath).readAsString();
expect(
generatedContent,
contains('String _renderFoo_partial_base_0(_i1.Foo context0) {'),
contains('String _renderFoo_partial_base_0(Foo context0) {'),
);
expect(
generatedContent,
contains('String _renderBar_partial_base_0(_i1.Bar context0) {'),
contains('String _renderBar_partial_base_0(Bar context0) {'),
);
});
}
Expand Down
78 changes: 40 additions & 38 deletions test/mustachio/aot_compiler_render_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ import 'annotations.dart';
var generatedContent = await File(
'${d.sandbox}/foo_package/lib/foo.aot_renderers_for_html.dart')
.readAsString();
generatedContent = generatedContent.replaceFirst(
"import 'foo.dart';", "import 'package:foo/foo.dart';");
renderScript.writeAsStringSync('''
import 'dart:io';

Expand Down Expand Up @@ -179,7 +181,7 @@ void main() {
() => [
d.dir('lib/templates/html', [d.file('foo.html', 'Text {{s1}}')]),
],
'_i1.Foo()..s1 = "<p>hello</p>"',
'Foo()..s1 = "<p>hello</p>"',
);
expect(output, equals('Text &lt;p&gt;hello&lt;&#47;p&gt;'));
});
Expand All @@ -189,7 +191,7 @@ void main() {
() => [
d.dir('lib/templates/html', [d.file('foo.html', 'Text {{{s1}}}')]),
],
'_i1.Foo()..s1 = "<p>hello</p>"',
'Foo()..s1 = "<p>hello</p>"',
);
expect(output, equals('Text <p>hello</p>'));
});
Expand All @@ -199,7 +201,7 @@ void main() {
() => [
d.dir('lib/templates/html', [d.file('foo.html', 'Text {{b1}}')]),
],
'_i1.Foo()..b1 = true',
'Foo()..b1 = true',
);
expect(output, equals('Text true'));
});
Expand All @@ -209,7 +211,7 @@ void main() {
() => [
d.dir('lib/templates/html', [d.file('foo.html', 'Text {{l1}}')]),
],
'_i1.Foo()..l1 = [1, 2, 3]',
'Foo()..l1 = [1, 2, 3]',
);
expect(output, equals('Text [1, 2, 3]'));
});
Expand All @@ -220,7 +222,7 @@ void main() {
d.dir('lib/templates/html',
[d.file('foo.html', 'Text {{#b1}}Section{{/b1}}')]),
],
'_i1.Foo()..b1 = true',
'Foo()..b1 = true',
);
expect(output, equals('Text Section'));
});
Expand All @@ -231,7 +233,7 @@ void main() {
d.dir('lib/templates/html',
[d.file('foo.html', 'Text {{#b1}}Section{{/b1}}')]),
],
'_i1.Foo()..b1 = false',
'Foo()..b1 = false',
);
expect(output, equals('Text '));
});
Expand All @@ -242,7 +244,7 @@ void main() {
d.dir('lib/templates/html',
[d.file('foo.html', 'Text {{#b1}}Section{{/b1}}')]),
],
'_i1.Foo()..b1 = false',
'Foo()..b1 = false',
);
expect(output, equals('Text '));
});
Expand All @@ -254,7 +256,7 @@ void main() {
d.dir('lib/templates/html',
[d.file('foo.html', 'Text {{^b1}}Section{{/b1}}')]),
],
'_i1.Foo()..b1 = true',
'Foo()..b1 = true',
);
expect(output, equals('Text '));
});
Expand All @@ -265,7 +267,7 @@ void main() {
d.dir('lib/templates/html',
[d.file('foo.html', 'Text {{^b1}}Section{{/b1}}')]),
],
'_i1.Foo()..b1 = false',
'Foo()..b1 = false',
);
expect(output, equals('Text Section'));
});
Expand All @@ -276,7 +278,7 @@ void main() {
d.dir('lib/templates/html',
[d.file('foo.html', 'Text {{#l1}}Num {{.}}, {{/l1}}')]),
],
'_i1.Foo()..l1 = [1, 2, 3]',
'Foo()..l1 = [1, 2, 3]',
);
expect(output, equals('Text Num 1, Num 2, Num 3, '));
});
Expand All @@ -288,7 +290,7 @@ void main() {
d.dir('lib/templates/html',
[d.file('bar.html', 'Text {{#foo.l1}}Num {{.}}, {{/foo.l1}}')]),
],
'_i1.Bar()..foo = (_i1.Foo()..l1 = [1, 2, 3])',
'Bar()..foo = (Foo()..l1 = [1, 2, 3])',
);
expect(output, equals('Text Num 1, Num 2, Num 3, '));
});
Expand All @@ -299,7 +301,7 @@ void main() {
d.dir('lib/templates/html',
[d.file('foo.html', 'Text {{#l1}}Num {{.}}, {{/l1}}')]),
],
'_i1.Foo()..l1 = []',
'Foo()..l1 = []',
);
expect(output, equals('Text '));
});
Expand All @@ -310,7 +312,7 @@ void main() {
d.dir('lib/templates/html',
[d.file('foo.html', 'Text {{^l1}}Empty{{/l1}}')]),
],
'_i1.Foo()..l1 = []',
'Foo()..l1 = []',
);
expect(output, equals('Text Empty'));
});
Expand All @@ -321,7 +323,7 @@ void main() {
d.dir('lib/templates/html',
[d.file('foo.html', 'Text {{^l1}}Empty{{/l1}}')]),
],
'_i1.Foo()..l1 = [1, 2, 3]',
'Foo()..l1 = [1, 2, 3]',
);
expect(output, equals('Text '));
});
Expand All @@ -332,7 +334,7 @@ void main() {
d.dir('lib/templates/html',
[d.file('bar.html', 'Text {{#foo}}Foo: {{s1}}{{/foo}}')]),
],
'_i1.Bar()..foo = (_i1.Foo()..s1 = "hello")',
'Bar()..foo = (Foo()..s1 = "hello")',
);
expect(output, equals('Text Foo: hello'));
});
Expand All @@ -344,7 +346,7 @@ void main() {
d.dir('lib/templates/html',
[d.file('bar.html', 'Text {{#foo}}One {{#s2}}Two{{/s2}}{{/foo}}')]),
],
'_i1.Bar()..foo = _i1.Foo()..s2 = "hello"',
'Bar()..foo = Foo()..s2 = "hello"',
);
expect(output, equals('Text One Two'));
});
Expand All @@ -355,7 +357,7 @@ void main() {
d.dir('lib/templates/html',
[d.file('foo.html', 'Text {{#s1}}"{{.}}" ({{length}}){{/s1}}')]),
],
'_i1.Foo()..s1 = null',
'Foo()..s1 = null',
);
expect(output, equals('Text '));
});
Expand All @@ -366,7 +368,7 @@ void main() {
d.dir('lib/templates/html',
[d.file('foo.html', 'Text {{^s1}}Section{{/s1}}')]),
],
'_i1.Foo()..s1 = "hello"',
'Foo()..s1 = "hello"',
);
expect(output, equals('Text '));
});
Expand All @@ -377,7 +379,7 @@ void main() {
d.dir('lib/templates/html',
[d.file('foo.html', 'Text {{^s1}}Section{{/s1}}')]),
],
'_i1.Foo()..s1 = null',
'Foo()..s1 = null',
);
expect(output, equals('Text Section'));
});
Expand All @@ -388,7 +390,7 @@ void main() {
d.dir('lib/templates/html',
[d.file('bar.html', 'Text {{#foo}}{{s1}}{{/foo}}')]),
],
'_i1.Bar()..foo = (_i1.Foo()..s1 = "hello")',
'Bar()..foo = (Foo()..s1 = "hello")',
);
expect(output, equals('Text hello'));
});
Expand All @@ -400,7 +402,7 @@ void main() {
d.dir('lib/templates/html',
[d.file('bar.html', 'Text {{#foo}}{{s2}}{{/foo}}')]),
],
'_i1.Bar()..foo = (_i1.Foo()..s1 = "hello")..s2 = "goodbye"',
'Bar()..foo = (Foo()..s1 = "hello")..s2 = "goodbye"',
);
expect(output, equals('Text goodbye'));
});
Expand All @@ -410,7 +412,7 @@ void main() {
() => [
d.dir('lib/templates/html', [d.file('bar.html', 'Text {{foo.s1}}')]),
],
'_i1.Bar()..foo = (_i1.Foo()..s1 = "hello")..s2 = "goodbye"',
'Bar()..foo = (Foo()..s1 = "hello")..s2 = "goodbye"',
);
expect(output, equals('Text hello'));
});
Expand All @@ -420,7 +422,7 @@ void main() {
() => [
d.dir('lib/templates/html', [d.file('foo.html', 'Text {{p1.p2.s}}')]),
],
'_i1.Foo()..p1 = (_i1.Property1()..p2 = (_i1.Property2()..s = "hello"))',
'Foo()..p1 = (Property1()..p2 = (Property2()..s = "hello"))',
);
expect(output, equals('Text hello'));
});
Expand All @@ -432,9 +434,9 @@ void main() {
d.dir(
'lib/templates/html', [d.file('foo.html', 'Text {{p1.p2.p3.s}}')]),
],
'_i1.Foo()'
'..p1 = (_i1.Property1()'
'..p2 = (_i1.Property2()..p3 = (_i1.Property3()..s = "hello")))',
'Foo()'
'..p1 = (Property1()'
'..p2 = (Property2()..p3 = (Property3()..s = "hello")))',
);
expect(output, equals('Text hello'));
});
Expand All @@ -445,7 +447,7 @@ void main() {
d.dir('lib/templates/html',
[d.file('bar.html', 'Text {{#foo}}{{foo.s1}}{{/foo}}')]),
],
'_i1.Bar()..foo = (_i1.Foo()..s1 = "hello")..s2 = "goodbye"',
'Bar()..foo = (Foo()..s1 = "hello")..s2 = "goodbye"',
);
expect(output, equals('Text hello'));
});
Expand All @@ -456,7 +458,7 @@ void main() {
d.dir('lib/templates/html',
[d.file('baz.html', 'Text {{#bar}}{{bar.foo.s1}}{{/bar}}')]),
],
'_i1.Baz()..bar = (_i1.Bar()..foo = (_i1.Foo()..s1 = "hello"))',
'Baz()..bar = (Bar()..foo = (Foo()..s1 = "hello"))',
);
expect(output, equals('Text hello'));
});
Expand All @@ -469,7 +471,7 @@ void main() {
d.file('baz.html', 'Text {{#bar}}{{bar.foo.baz.bar.foo.s1}}{{/bar}}')
]),
],
'_i1.Baz()..bar = (_i1.Bar()..foo = (_i1.Foo()..s1 = "hello"));'
'Baz()..bar = (Bar()..foo = (Foo()..s1 = "hello"));'
'baz.bar!.foo!.baz = baz',
);
expect(output, equals('Text hello'));
Expand All @@ -483,7 +485,7 @@ void main() {
d.file('_foo.mustache.html', 'Partial {{s1}}'),
]),
],
'_i1.Bar()..foo = (_i1.Foo()..s1 = "hello")',
'Bar()..foo = (Foo()..s1 = "hello")',
);
expect(output, equals('Text Partial hello'));
});
Expand All @@ -498,7 +500,7 @@ void main() {
d.file('_foo.mustache.html', 'Partial {{s1}}'),
]),
],
'_i1.Bar()..foo = (_i1.Foo()..s1 = "hello")',
'Bar()..foo = (Foo()..s1 = "hello")',
);
expect(output, equals('Text Partial hello'));
});
Expand All @@ -515,7 +517,7 @@ void main() {
d.file('_foo.mustache.html', 'Partial {{s2}}'),
]),
],
'_i1.Bar()..foo = (_i1.Foo()..s1 = "hello")..s2 = "goodbye"',
'Bar()..foo = (Foo()..s1 = "hello")..s2 = "goodbye"',
);
expect(output, equals('Text Partial goodbye'));
});
Expand All @@ -530,7 +532,7 @@ void main() {
d.file('_foo_l1.mustache.html', 'p2 {{.}}, '),
]),
],
'_i1.Bar()..foo = (_i1.Foo()..s1 = "hello"..l1 = [1, 2, 3])',
'Bar()..foo = (Foo()..s1 = "hello"..l1 = [1, 2, 3])',
);
expect(output, equals('Text, p1, p2 1, p2 2, p2 3, '));
});
Expand All @@ -552,7 +554,7 @@ void main() {
() => [
d.dir('lib/templates/html', [d.file('foo.html', 'Text {{s2}}')]),
],
'_i1.Foo()',
'Foo()',
),
throwsA(const TypeMatcher<MustachioResolutionError>()
.having((e) => e.message, 'message', contains('''
Expand All @@ -571,7 +573,7 @@ line 1, column 8 of lib/templates/html/foo.html: Failed to resolve '[s2]' as a p
d.dir('lib/templates/html',
[d.file('foo.html', 'Text {{#s2}}Section{{/s2}}')]),
],
'_i1.Foo()',
'Foo()',
),
throwsA(const TypeMatcher<MustachioResolutionError>()
.having((e) => e.message, 'message', contains('''
Expand All @@ -590,7 +592,7 @@ line 1, column 9 of lib/templates/html/foo.html: Failed to resolve '[s2]' as a p
() => [
d.dir('lib/templates/html', [d.file('bar.html', 'Text {{foo.x}}')]),
],
'_i1.Bar()..foo = _i1.Foo()',
'Bar()..foo = Foo()',
),
throwsA(const TypeMatcher<MustachioResolutionError>()
.having((e) => e.message, 'message', contains('''
Expand All @@ -610,7 +612,7 @@ line 1, column 8 of lib/templates/html/bar.html: Failed to resolve 'x' on Bar wh
d.dir('lib/templates/html',
[d.file('bar.html', 'Text {{#foo.x}}Section{{/foo.x}}')]),
],
'_i1.Bar()..foo = _i1.Foo()',
'Bar()..foo = Foo()',
),
throwsA(const TypeMatcher<MustachioResolutionError>()
.having((e) => e.message, 'message', contains('''
Expand All @@ -634,7 +636,7 @@ line 1, column 13 of lib/templates/html/bar.html: Failed to resolve '[x]' as a p
d.file('bar.html', 'Text {{#foo}}{{>missing.mustache}}{{/foo}}')
]),
],
'_i1.Bar()',
'Bar()',
),
throwsA(const TypeMatcher<PathNotFoundException>()),
);
Expand Down
Loading