Skip to content

Commit 5b29121

Browse files
committed
fix(filters): pass filters to all evals
closes dart-archive#755 Ad support for '"s" + ("m"|filter) + "e"'
1 parent d1c6eb1 commit 5b29121

File tree

5 files changed

+19
-16
lines changed

5 files changed

+19
-16
lines changed

bin/parser_generator_for_spec.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ main(arguments) {
175175
'add(a,b)',
176176
'notAProperty',
177177
"'Foo'|uppercase",
178+
"'f' + ('o'|uppercase) + 'o'",
178179
"1|increment:2",
179180
"'abcd'|substring:1:offset",
180181
"'abcd'|substring:1:3|uppercase",

lib/core/parser/eval.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,26 @@ class Conditional extends syntax.Conditional {
3939
Conditional(syntax.Expression condition,
4040
syntax.Expression yes, syntax.Expression no)
4141
: super(condition, yes, no);
42-
eval(scope, [FilterMap filters]) => toBool(condition.eval(scope))
43-
? yes.eval(scope)
44-
: no.eval(scope);
42+
eval(scope, [FilterMap filters]) => toBool(condition.eval(scope, filters))
43+
? yes.eval(scope, filters)
44+
: no.eval(scope, filters);
4545
}
4646

4747
class PrefixNot extends syntax.Prefix {
4848
PrefixNot(syntax.Expression expression) : super('!', expression);
49-
eval(scope, [FilterMap filters]) => !toBool(expression.eval(scope));
49+
eval(scope, [FilterMap filters]) => !toBool(expression.eval(scope, filters));
5050
}
5151

5252
class Binary extends syntax.Binary {
5353
Binary(String operation, syntax.Expression left, syntax.Expression right):
5454
super(operation, left, right);
5555
eval(scope, [FilterMap filters]) {
56-
var left = this.left.eval(scope);
56+
var left = this.left.eval(scope, filters);
5757
switch (operation) {
58-
case '&&': return toBool(left) && toBool(this.right.eval(scope));
59-
case '||': return toBool(left) || toBool(this.right.eval(scope));
58+
case '&&': return toBool(left) && toBool(this.right.eval(scope, filters));
59+
case '||': return toBool(left) || toBool(this.right.eval(scope, filters));
6060
}
61-
var right = this.right.eval(scope);
61+
var right = this.right.eval(scope, filters);
6262

6363
// Null check for the operations.
6464
if (left == null || right == null) {

lib/core/parser/eval_calls.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@ class CallScope extends syntax.CallScope with CallReflective {
1212
CallScope(name, arguments)
1313
: super(name, arguments),
1414
symbol = newSymbol(name);
15-
eval(scope, [FilterMap filters]) => _eval(scope, scope);
15+
eval(scope, [FilterMap filters]) => _eval(scope, scope, filters);
1616
}
1717

1818
class CallMember extends syntax.CallMember with CallReflective {
1919
final Symbol symbol;
2020
CallMember(object, name, arguments)
2121
: super(object, name, arguments),
2222
symbol = newSymbol(name);
23-
eval(scope, [FilterMap filters]) => _eval(scope, object.eval(scope, filters));
23+
eval(scope, [FilterMap filters]) => _eval(scope, object.eval(scope, filters),
24+
filters);
2425
}
2526

2627
class CallScopeFast0 extends syntax.CallScope with CallFast {
@@ -106,13 +107,12 @@ abstract class CallReflective {
106107
Symbol get symbol;
107108
syntax.CallArguments get arguments;
108109

109-
// TODO(kasperl): This seems broken -- it needs filters.
110-
_eval(scope, holder) {
111-
List positionals = evalList(scope, arguments.positionals);
110+
_eval(scope, holder, FilterMap filters) {
111+
List positionals = evalList(scope, arguments.positionals, filters);
112112
if (arguments.named.isNotEmpty) {
113113
var named = new Map<Symbol, dynamic>();
114114
arguments.named.forEach((String name, value) {
115-
named[new Symbol(name)] = value.eval(scope);
115+
named[new Symbol(name)] = value.eval(scope, filters);
116116
});
117117
if (holder is Map) {
118118
var fn = ensureFunctionFromMap(holder, name);

lib/core/parser/utils.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ class EvalError {
2121

2222
/// Evaluate the [list] in context of the [scope].
2323
List evalList(scope, List<Expression> list, [FilterMap filters]) {
24-
int length = list.length;
25-
for (int cacheLength = _evalListCache.length; cacheLength <= length; cacheLength++) {
24+
final length = list.length;
25+
int cacheLength = _evalListCache.length;
26+
for (; cacheLength <= length; cacheLength++) {
2627
_evalListCache.add(new List(cacheLength));
2728
}
2829
List result = _evalListCache[length];

test/core/parser/parser_spec.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,7 @@ main() {
11021102
describe('filters', () {
11031103
it('should call a filter', () {
11041104
expect(eval("'Foo'|uppercase", filters)).toEqual("FOO");
1105+
expect(eval("'f' + ('o'|uppercase) + 'o'", filters)).toEqual("fOo");
11051106
expect(eval("'fOo'|uppercase|lowercase", filters)).toEqual("foo");
11061107
});
11071108

0 commit comments

Comments
 (0)