diff --git a/lib/core/scope.dart b/lib/core/scope.dart index 83678fccd..5bdef9d96 100644 --- a/lib/core/scope.dart +++ b/lib/core/scope.dart @@ -205,17 +205,21 @@ class Scope { assert(expression is String); Watch watch; ReactionFn fn = reactionFn; - if (expression.startsWith('::')) { - expression = expression.substring(2); - fn = (value, last) { - if (value != null) { - watch.remove(); - return reactionFn(value, last); - } - }; - } else if (expression.startsWith(':')) { - expression = expression.substring(1); - fn = (value, last) => value == null ? null : reactionFn(value, last); + if (expression.isEmpty) { + expression = '""'; + } else { + if (expression.startsWith('::')) { + expression = expression.substring(2); + fn = (value, last) { + if (value != null) { + watch.remove(); + return reactionFn(value, last); + } + }; + } else if (expression.startsWith(':')) { + expression = expression.substring(1); + fn = (value, last) => value == null ? null : reactionFn(value, last); + } } AST ast = rootScope._astParser(expression, context: context, diff --git a/test/core/scope_spec.dart b/test/core/scope_spec.dart index 1382bd89b..377075044 100644 --- a/test/core/scope_spec.dart +++ b/test/core/scope_spec.dart @@ -66,12 +66,14 @@ void main() { it('should watch literals', (Logger logger, Map context, RootScope rootScope) { context['a'] = 1; rootScope + ..watch('', (value, previous) => logger(value)) + ..watch('""', (value, previous) => logger(value)) ..watch('1', (value, previous) => logger(value)) ..watch('"str"', (value, previous) => logger(value)) ..watch('[a, 2, 3]', (value, previous) => logger(value)) ..watch('{a:a, b:2}', (value, previous) => logger(value)) ..digest(); - expect(logger).toEqual([1, 'str', [1, 2, 3], {'a': 1, 'b': 2}]); + expect(logger).toEqual(['', '', 1, 'str', [1, 2, 3], {'a': 1, 'b': 2}]); logger.clear(); context['a'] = 3; rootScope.digest();