diff --git a/third_party/packages/mustache_template/CHANGELOG.md b/third_party/packages/mustache_template/CHANGELOG.md index 83bf7da3b5b3..67f53c1a8fc9 100644 --- a/third_party/packages/mustache_template/CHANGELOG.md +++ b/third_party/packages/mustache_template/CHANGELOG.md @@ -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 diff --git a/third_party/packages/mustache_template/lib/src/lambda_context.dart b/third_party/packages/mustache_template/lib/src/lambda_context.dart index ca4082f0ea33..3cd72c3ee092 100644 --- a/third_party/packages/mustache_template/lib/src/lambda_context.dart +++ b/third_party/packages/mustache_template/lib/src/lambda_context.dart @@ -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.', ); } @@ -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); } diff --git a/third_party/packages/mustache_template/lib/src/parser.dart b/third_party/packages/mustache_template/lib/src/parser.dart index a6dc3b1e8b29..4253ec312aa4 100644 --- a/third_party/packages/mustache_template/lib/src/parser.dart +++ b/third_party/packages/mustache_template/lib/src/parser.dart @@ -98,8 +98,7 @@ class Parser { _parseLine(); default: - // TODO(stuartmorgan): Convert to StateError. - throw Exception('Unreachable code.'); + throw StateError('Unreachable code.'); } } @@ -212,8 +211,7 @@ class Parser { break; default: - // TODO(stuartmorgan): Convert to StateError. - throw Exception('Unreachable code.'); + throw StateError('Unreachable code.'); } } @@ -412,8 +410,7 @@ class Parser { node = null; default: - // TODO(stuartmorgan): Convert to StateError. - throw Exception('Unreachable code'); + throw StateError('Unreachable code.'); } return node; } diff --git a/third_party/packages/mustache_template/pubspec.yaml b/third_party/packages/mustache_template/pubspec.yaml index 30e2128afb1e..264e0ee0c4d4 100644 --- a/third_party/packages/mustache_template/pubspec.yaml +++ b/third_party/packages/mustache_template/pubspec.yaml @@ -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 diff --git a/third_party/packages/mustache_template/test/mustache_test.dart b/third_party/packages/mustache_template/test/mustache_test.dart index 5fffe6502884..a8149220ba76 100644 --- a/third_party/packages/mustache_template/test/mustache_test.dart +++ b/third_party/packages/mustache_template/test/mustache_test.dart @@ -883,6 +883,29 @@ void main() { const output = ''; expect(parse(template).renderString(values), equals(output)); }); + + test('LambdaContext renderString on non-section throws', () { + final t = Template('{{ foo }}'); + expect( + () => t.renderString({ + 'foo': (LambdaContext lc) => lc.renderString(), + }), + throwsA(isA()), + ); + }); + + test('LambdaContext render on non-section throws', () { + final t = Template('{{ foo }}'); + expect( + () => t.renderString({ + 'foo': (LambdaContext lc) { + lc.render(); + return ''; + }, + }), + throwsA(isA()), + ); + }); }); }