Skip to content

Commit 8934e55

Browse files
authored
Some minor mustachio cleanup (#2514)
1 parent 60bb05a commit 8934e55

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

lib/src/mustachio/parser.dart

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class MustachioParser {
177177
///
178178
/// [_index] should be at the character immediately following the `#`
179179
/// character which opens a possible section tag.
180-
_TagParseResult _parseSection({@required invert}) {
180+
_TagParseResult _parseSection({@required bool invert}) {
181181
var parsedKey = _parseKey();
182182
if (parsedKey.type == _KeyParseResultType.notKey) {
183183
return _TagParseResult.notTag;
@@ -407,6 +407,7 @@ enum _TagParseResultType {
407407
}
408408

409409
/// The result of attempting to parse a Mustache tag.
410+
@immutable
410411
class _TagParseResult {
411412
final _TagParseResultType type;
412413

@@ -432,15 +433,15 @@ class _TagParseResult {
432433

433434
/// A [_TagParseResult] representing that EOF was reached, without parsing a
434435
/// tag.
435-
static _TagParseResult endOfFile =
436+
static final _TagParseResult endOfFile =
436437
_TagParseResult(_TagParseResultType.endOfFile, null, null);
437438

438439
/// A [_TagParseResult] representing that a tag was not parsed.
439-
static _TagParseResult notTag =
440+
static final _TagParseResult notTag =
440441
_TagParseResult(_TagParseResultType.notTag, null, null);
441442

442443
/// A [_TagParseResult] representing that a comment tag was parsed.
443-
static _TagParseResult commentTag =
444+
static final _TagParseResult commentTag =
444445
_TagParseResult(_TagParseResultType.commentTag, null, null);
445446
}
446447

@@ -452,12 +453,13 @@ enum _KeyParseResultType {
452453
}
453454

454455
/// The result of attempting to parse a Mustache key.
456+
@immutable
455457
class _KeyParseResult {
456458
final _KeyParseResultType type;
457459

458460
final List<String> names;
459461

460-
_KeyParseResult._(this.type, this.names);
462+
const _KeyParseResult._(this.type, this.names);
461463

462464
factory _KeyParseResult(_KeyParseResultType type, String key) {
463465
if (key == '.') {
@@ -469,12 +471,12 @@ class _KeyParseResult {
469471

470472
/// A [_KeyParseResult] representing that EOF was reached, without parsing a
471473
/// key.
472-
static _KeyParseResult endOfFile =
473-
_KeyParseResult._(_KeyParseResultType.endOfFile, null);
474+
static const _KeyParseResult endOfFile =
475+
_KeyParseResult._(_KeyParseResultType.endOfFile, []);
474476

475477
/// A [_KeyParseResult] representing that a key was not parsed.
476-
static _KeyParseResult notKey =
477-
_KeyParseResult._(_KeyParseResultType.notKey, null);
478+
static const _KeyParseResult notKey =
479+
_KeyParseResult._(_KeyParseResultType.notKey, []);
478480

479481
/// The reconstituted key, with periods separating names.
480482
String get joinedNames => names.join('.');

lib/src/mustachio/renderer_base.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ class SimpleRenderer extends RendererBase<Object> {
289289

290290
/// An individual property of objects of type [T], including functions for
291291
/// rendering various types of Mustache nodes.
292+
@immutable
292293
class Property<T> {
293294
/// Gets the value of this property on the object [context].
294295
final Object /*?*/ Function(T context) /*!*/ getValue;
@@ -338,7 +339,7 @@ class Property<T> {
338339

339340
/// An error indicating that a renderer failed to resolve a key.
340341
class MustachioResolutionError extends Error {
341-
String message;
342+
final String message;
342343

343344
MustachioResolutionError([this.message]);
344345

@@ -349,9 +350,9 @@ class MustachioResolutionError extends Error {
349350
/// An error indicating that a renderer failed to resolve a follow-on name in a
350351
/// multi-name key.
351352
class PartialMustachioResolutionError extends Error {
352-
String name;
353+
final String name;
353354

354-
Type contextType;
355+
final Type contextType;
355356

356357
PartialMustachioResolutionError(this.name, this.contextType);
357358
}

0 commit comments

Comments
 (0)