Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: third_party/pkg/angular/lib/core/parser/eval.dart

Issue 257423008: Update all Angular libs (run update_all.sh). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 library angular.core.parser.eval; 1 library angular.core.parser.eval;
2 2
3 import 'package:angular/core/parser/syntax.dart' as syntax; 3 import 'package:angular/core/parser/syntax.dart' as syntax;
4 import 'package:angular/core/parser/utils.dart'; 4 import 'package:angular/core/parser/utils.dart';
5 import 'package:angular/core/module.dart'; 5 import 'package:angular/core/module_internal.dart';
6 6
7 export 'package:angular/core/parser/eval_access.dart'; 7 export 'package:angular/core/parser/eval_access.dart';
8 export 'package:angular/core/parser/eval_calls.dart'; 8 export 'package:angular/core/parser/eval_calls.dart';
9 9
10 class Chain extends syntax.Chain { 10 class Chain extends syntax.Chain {
11 Chain(List<syntax.Expression> expressions) : super(expressions); 11 Chain(List<syntax.Expression> expressions) : super(expressions);
12 eval(scope, [FilterMap filters]) { 12 eval(scope, [FormatterMap formatters]) {
13 var result; 13 var result;
14 for (int i = 0; i < expressions.length; i++) { 14 for (int i = 0; i < expressions.length; i++) {
15 var last = expressions[i].eval(scope, filters); 15 var last = expressions[i].eval(scope, formatters);
16 if (last != null) result = last; 16 if (last != null) result = last;
17 } 17 }
18 return result; 18 return result;
19 } 19 }
20 } 20 }
21 21
22 class Filter extends syntax.Filter { 22 class Filter extends syntax.Filter {
23 final List allArguments; 23 final List<syntax.Expression> allArguments;
24 Filter(syntax.Expression expression, String name, List<syntax.Expression> argu ments, 24 Filter(syntax.Expression expression, String name, List<syntax.Expression> argu ments,
25 List<syntax.Expression> this.allArguments) 25 this.allArguments)
26 : super(expression, name, arguments); 26 : super(expression, name, arguments);
27 27
28 eval(scope, [FilterMap filters]) => 28 eval(scope, [FormatterMap formatters]) =>
29 Function.apply(filters(name), evalList(scope, allArguments, filters)); 29 Function.apply(formatters(name), evalList(scope, allArguments, formatters) );
30 } 30 }
31 31
32 class Assign extends syntax.Assign { 32 class Assign extends syntax.Assign {
33 Assign(syntax.Expression target, value) : super(target, value); 33 Assign(syntax.Expression target, value) : super(target, value);
34 eval(scope, [FilterMap filters]) => 34 eval(scope, [FormatterMap formatters]) =>
35 target.assign(scope, value.eval(scope, filters)); 35 target.assign(scope, value.eval(scope, formatters));
36 } 36 }
37 37
38 class Conditional extends syntax.Conditional { 38 class Conditional extends syntax.Conditional {
39 Conditional(syntax.Expression condition, 39 Conditional(syntax.Expression condition,
40 syntax.Expression yes, syntax.Expression no): super(condition, yes , no); 40 syntax.Expression yes, syntax.Expression no)
41 eval(scope, [FilterMap filters]) => toBool(condition.eval(scope)) 41 : super(condition, yes, no);
42 ? yes.eval(scope) 42 eval(scope, [FormatterMap formatters]) => toBool(condition.eval(scope, formatt ers))
43 : no.eval(scope); 43 ? yes.eval(scope, formatters)
44 : no.eval(scope, formatters);
44 } 45 }
45 46
46 class PrefixNot extends syntax.Prefix { 47 class PrefixNot extends syntax.Prefix {
47 PrefixNot(syntax.Expression expression) : super('!', expression); 48 PrefixNot(syntax.Expression expression) : super('!', expression);
48 eval(scope, [FilterMap filters]) => !toBool(expression.eval(scope)); 49 eval(scope, [FormatterMap formatters]) => !toBool(expression.eval(scope, forma tters));
49 } 50 }
50 51
51 class Binary extends syntax.Binary { 52 class Binary extends syntax.Binary {
52 Binary(String operation, syntax.Expression left, syntax.Expression right): 53 Binary(String operation, syntax.Expression left, syntax.Expression right):
53 super(operation, left, right); 54 super(operation, left, right);
54 eval(scope, [FilterMap filters]) { 55 eval(scope, [FormatterMap formatters]) {
55 var left = this.left.eval(scope); 56 var left = this.left.eval(scope, formatters);
56 switch (operation) { 57 switch (operation) {
57 case '&&': return toBool(left) && toBool(this.right.eval(scope)); 58 case '&&': return toBool(left) && toBool(this.right.eval(scope, formatters ));
58 case '||': return toBool(left) || toBool(this.right.eval(scope)); 59 case '||': return toBool(left) || toBool(this.right.eval(scope, formatters ));
59 } 60 }
60 var right = this.right.eval(scope); 61 var right = this.right.eval(scope, formatters);
62
63 // Null check for the operations.
64 if (left == null || right == null) {
65 switch (operation) {
66 case '+':
67 if (left != null) return left;
68 if (right != null) return right;
69 return 0;
70 case '-':
71 if (left != null) return left;
72 if (right != null) return 0 - right;
73 return 0;
74 }
75 return null;
76 }
77
61 switch (operation) { 78 switch (operation) {
62 case '+' : return autoConvertAdd(left, right); 79 case '+' : return autoConvertAdd(left, right);
63 case '-' : return left - right; 80 case '-' : return left - right;
64 case '*' : return left * right; 81 case '*' : return left * right;
65 case '/' : return left / right; 82 case '/' : return left / right;
66 case '~/' : return left ~/ right; 83 case '~/' : return left ~/ right;
67 case '%' : return left % right; 84 case '%' : return left % right;
68 case '==' : return left == right; 85 case '==' : return left == right;
69 case '!=' : return left != right; 86 case '!=' : return left != right;
70 case '<' : return left < right; 87 case '<' : return left < right;
71 case '>' : return left > right; 88 case '>' : return left > right;
72 case '<=' : return left <= right; 89 case '<=' : return left <= right;
73 case '>=' : return left >= right; 90 case '>=' : return left >= right;
74 case '^' : return left ^ right; 91 case '^' : return left ^ right;
75 case '&' : return left & right; 92 case '&' : return left & right;
76 } 93 }
77 throw new EvalError('Internal error [$operation] not handled'); 94 throw new EvalError('Internal error [$operation] not handled');
78 } 95 }
79 } 96 }
80 97
81 class LiteralPrimitive extends syntax.LiteralPrimitive { 98 class LiteralPrimitive extends syntax.LiteralPrimitive {
82 LiteralPrimitive(dynamic value) : super(value); 99 LiteralPrimitive(dynamic value) : super(value);
83 eval(scope, [FilterMap filters]) => value; 100 eval(scope, [FormatterMap formatters]) => value;
84 } 101 }
85 102
86 class LiteralString extends syntax.LiteralString { 103 class LiteralString extends syntax.LiteralString {
87 LiteralString(String value) : super(value); 104 LiteralString(String value) : super(value);
88 eval(scope, [FilterMap filters]) => value; 105 eval(scope, [FormatterMap formatters]) => value;
89 } 106 }
90 107
91 class LiteralArray extends syntax.LiteralArray { 108 class LiteralArray extends syntax.LiteralArray {
92 LiteralArray(List<syntax.Expression> elements) : super(elements); 109 LiteralArray(List<syntax.Expression> elements) : super(elements);
93 eval(scope, [FilterMap filters]) => 110 eval(scope, [FormatterMap formatters]) =>
94 elements.map((e) => e.eval(scope, filters)).toList(); 111 elements.map((e) => e.eval(scope, formatters)).toList();
95 } 112 }
96 113
97 class LiteralObject extends syntax.LiteralObject { 114 class LiteralObject extends syntax.LiteralObject {
98 LiteralObject(List<String> keys, List<syntax.Expression>values) : super(keys, values); 115 LiteralObject(List<String> keys, List<syntax.Expression>values) : super(keys, values);
99 eval(scope, [FilterMap filters]) => 116 eval(scope, [FormatterMap formatters]) =>
100 new Map.fromIterables(keys, values.map((e) => e.eval(scope, filters))); 117 new Map.fromIterables(keys, values.map((e) => e.eval(scope, formatters)));
101 } 118 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698