OLD | NEW |
1 library angular.core.parser.utils; | 1 library angular.core.parser.utils; |
2 | 2 |
3 import 'package:angular/core/parser/syntax.dart' show Expression; | 3 import 'package:angular/core/parser/syntax.dart' show Expression; |
4 import 'package:angular/core/module.dart'; | 4 import 'package:angular/core/module_internal.dart'; |
5 import 'package:angular/utils.dart' show isReservedWord; | |
6 export 'package:angular/utils.dart' show relaxFnApply, relaxFnArgs, toBool; | 5 export 'package:angular/utils.dart' show relaxFnApply, relaxFnArgs, toBool; |
7 | 6 |
8 /// Marker for an uninitialized value. | 7 /// Marker for an uninitialized value. |
9 const UNINITIALIZED = const _Uninitialized(); | 8 const UNINITIALIZED = const _Uninitialized(); |
10 class _Uninitialized { const _Uninitialized(); } | 9 class _Uninitialized { const _Uninitialized(); } |
11 | 10 |
12 class EvalError { | 11 class EvalError { |
13 final String message; | 12 final String message; |
14 EvalError(this.message); | 13 EvalError(this.message); |
15 | 14 |
16 String unwrap(String input, stack) { | 15 String unwrap(String input, stack) { |
17 String location = (stack == null) ? '' : '\n\nFROM:\n$stack'; | 16 String location = (stack == null) ? '' : '\n\nFROM:\n$stack'; |
18 return 'Eval Error: $message while evaling [$input]$location'; | 17 return 'Eval Error: $message while evaling [$input]$location'; |
19 } | 18 } |
20 } | 19 } |
21 | 20 |
22 /// Evaluate the [list] in context of the [scope]. | 21 /// Evaluate the [list] in context of the [scope]. |
23 List evalList(scope, List<Expression> list, [FilterMap filters]) { | 22 List evalList(scope, List<Expression> list, [FormatterMap formatters]) { |
24 int length = list.length; | 23 final length = list.length; |
25 for (int cacheLength = _evalListCache.length; cacheLength <= length; cacheLeng
th++) { | 24 int cacheLength = _evalListCache.length; |
| 25 for (; cacheLength <= length; cacheLength++) { |
26 _evalListCache.add(new List(cacheLength)); | 26 _evalListCache.add(new List(cacheLength)); |
27 } | 27 } |
28 List result = _evalListCache[length]; | 28 List result = _evalListCache[length]; |
29 for (int i = 0; i < length; i++) { | 29 for (int i = 0; i < length; i++) { |
30 result[i] = list[i].eval(scope, filters); | 30 result[i] = list[i].eval(scope, formatters); |
31 } | 31 } |
32 return result; | 32 return result; |
33 } | 33 } |
34 final List _evalListCache = [[],[0],[0,0],[0,0,0],[0,0,0,0],[0,0,0,0,0]]; | 34 final List _evalListCache = [[],[0],[0,0],[0,0,0],[0,0,0,0],[0,0,0,0,0]]; |
35 | 35 |
36 /// Add the two arguments with automatic type conversion. | 36 /// Add the two arguments with automatic type conversion. |
37 autoConvertAdd(a, b) { | 37 autoConvertAdd(a, b) { |
38 if (a != null && b != null) { | 38 if (a != null && b != null) { |
39 // TODO(deboer): Support others. | 39 // TODO(deboer): Support others. |
40 if (a is String && b is! String) { | 40 if (a is String && b is! String) { |
41 return a + b.toString(); | 41 return a + b.toString(); |
42 } | 42 } |
43 if (a is! String && b is String) { | 43 if (a is! String && b is String) { |
44 return a.toString() + b; | 44 return a.toString() + b; |
45 } | 45 } |
46 return a + b; | 46 return a + b; |
47 } | 47 } |
48 if (a != null) return a; | 48 if (a != null) return a; |
49 if (b != null) return b; | 49 if (b != null) return b; |
50 return null; | 50 return 0; |
51 } | 51 } |
52 | 52 |
53 /** | 53 /** |
54 * Ensures that the given [function] is a function and return it. Throws | 54 * Ensures that the given [function] is a function and return it. Throws |
55 * an [EvalError] if it isn't. | 55 * an [EvalError] if it isn't. |
56 */ | 56 */ |
57 Function ensureFunction(function, String name) { | 57 Function ensureFunction(function, String name) { |
58 if (function is Function) return function; | 58 if (function is Function) return function; |
59 if (function == null) { | 59 if (function == null) { |
60 throw new EvalError("Undefined function $name"); | 60 throw new EvalError("Undefined function $name"); |
(...skipping 29 matching lines...) Expand all Loading... |
90 int index = key.toInt(); | 90 int index = key.toInt(); |
91 if (object.length <= index) object.length = index + 1; | 91 if (object.length <= index) object.length = index + 1; |
92 object[index] = value; | 92 object[index] = value; |
93 } else if (object is Map) { | 93 } else if (object is Map) { |
94 object["$key"] = value; // toString dangerous? | 94 object["$key"] = value; // toString dangerous? |
95 } else { | 95 } else { |
96 object[key] = value; | 96 object[key] = value; |
97 } | 97 } |
98 return value; | 98 return value; |
99 } | 99 } |
100 | |
101 /// Returns a new symbol with the given name if the name is a legal | |
102 /// symbol name. Otherwise, returns null. | |
103 Symbol newSymbol(String name) { | |
104 return isReservedWord(name) ? null : new Symbol(name); | |
105 } | |
OLD | NEW |