Skip to content
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 changes: 3 additions & 1 deletion third_party/packages/mustache_template/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## NEXT
## 2.0.3

* Updates minimum supported SDK version to Flutter 3.35/Dart 3.9.
* Fixes error handling in LambdaContext by adding missing throw statements.
* Uses StateError instead of Exception for unreachable code in parser.

## 2.0.2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ class LambdaContext implements m.LambdaContext {
String renderString({Object? value}) {
_checkClosed();
if (_node is! SectionNode) {
// TODO(stuartmorgan): Fix the lack of `throw` here, which looks like a
// bug in the original code.
_error(
throw _error(
'LambdaContext.renderString() can only be called on section tags.',
);
}
Expand All @@ -62,9 +60,9 @@ class LambdaContext implements m.LambdaContext {
void render({Object? value}) {
_checkClosed();
if (_node is! SectionNode) {
// TODO(stuartmorgan): Fix the lack of `throw` here, which looks like a
// bug in the original code.
_error('LambdaContext.render() can only be called on section tags.');
throw _error(
'LambdaContext.render() can only be called on section tags.',
);
}
_renderSubtree(_renderer.sink, value);
}
Expand Down
9 changes: 3 additions & 6 deletions third_party/packages/mustache_template/lib/src/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ class Parser {
_parseLine();

default:
// TODO(stuartmorgan): Convert to StateError.
throw Exception('Unreachable code.');
throw StateError('Unreachable code.');
}
}

Expand Down Expand Up @@ -212,8 +211,7 @@ class Parser {
break;

default:
// TODO(stuartmorgan): Convert to StateError.
throw Exception('Unreachable code.');
throw StateError('Unreachable code.');
}
}

Expand Down Expand Up @@ -412,8 +410,7 @@ class Parser {
node = null;

default:
// TODO(stuartmorgan): Convert to StateError.
throw Exception('Unreachable code');
throw StateError('Unreachable code.');
}
return node;
}
Expand Down
2 changes: 1 addition & 1 deletion third_party/packages/mustache_template/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: mustache_template
description: A templating library that implements the Mustache template specification
repository: https://github.com/flutter/packages/tree/main/third_party/packages/mustache_template
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+mustache_template%22
version: 2.0.2
version: 2.0.3

environment:
sdk: ^3.9.0
Expand Down
23 changes: 23 additions & 0 deletions third_party/packages/mustache_template/test/mustache_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,29 @@ void main() {
const output = '<oi!>';
expect(parse(template).renderString(values), equals(output));
});

test('LambdaContext renderString on non-section throws', () {
final t = Template('{{ foo }}');
expect(
() => t.renderString(<String, Object>{
'foo': (LambdaContext lc) => lc.renderString(),
}),
throwsA(isA<TemplateException>()),
);
});

test('LambdaContext render on non-section throws', () {
final t = Template('{{ foo }}');
expect(
() => t.renderString(<String, Object>{
'foo': (LambdaContext lc) {
lc.render();
return '';
},
}),
throwsA(isA<TemplateException>()),
);
});
});
}

Expand Down