| 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'; | |
| 5 import 'package:angular/utils.dart' show isReservedWord; | |
| 6 export 'package:angular/utils.dart' show relaxFnApply, relaxFnArgs, toBool; | 4 export 'package:angular/utils.dart' show relaxFnApply, relaxFnArgs, toBool; |
| 7 | 5 |
| 8 /// Marker for an uninitialized value. | 6 /// Marker for an uninitialized value. |
| 9 const UNINITIALIZED = const _Uninitialized(); | 7 const UNINITIALIZED = const _Uninitialized(); |
| 10 class _Uninitialized { const _Uninitialized(); } | 8 class _Uninitialized { const _Uninitialized(); } |
| 11 | 9 |
| 12 class EvalError { | 10 class EvalError { |
| 13 final String message; | 11 final String message; |
| 14 EvalError(this.message); | 12 EvalError(this.message); |
| 15 | 13 |
| 16 String unwrap(String input, stack) { | 14 String unwrap(String input, stack) { |
| 17 String location = (stack == null) ? '' : '\n\nFROM:\n$stack'; | 15 String location = (stack == null) ? '' : '\n\nFROM:\n$stack'; |
| 18 return 'Eval Error: $message while evaling [$input]$location'; | 16 return 'Eval Error: $message while evaling [$input]$location'; |
| 19 } | 17 } |
| 20 } | 18 } |
| 21 | 19 |
| 22 /// Evaluate the [list] in context of the [scope]. | 20 /// Evaluate the [list] in context of the [scope]. |
| 23 List evalList(scope, List<Expression> list, [FilterMap filters]) { | 21 List evalList(scope, List<Expression> list) { |
| 24 int length = list.length; | 22 int length = list.length; |
| 25 for (int cacheLength = _evalListCache.length; cacheLength <= length; cacheLeng
th++) { | 23 for(int cacheLength = _evalListCache.length; cacheLength <= length; cacheLengt
h++) { |
| 26 _evalListCache.add(new List(cacheLength)); | 24 _evalListCache.add(new List(cacheLength)); |
| 27 } | 25 } |
| 28 List result = _evalListCache[length]; | 26 List result = _evalListCache[length]; |
| 29 for (int i = 0; i < length; i++) { | 27 for (int i = 0; i < length; i++) { |
| 30 result[i] = list[i].eval(scope, filters); | 28 result[i] = list[i].eval(scope); |
| 31 } | 29 } |
| 32 return result; | 30 return result; |
| 33 } | 31 } |
| 34 final List _evalListCache = [[],[0],[0,0],[0,0,0],[0,0,0,0],[0,0,0,0,0]]; | 32 final List _evalListCache = [[],[0],[0,0],[0,0,0],[0,0,0,0],[0,0,0,0,0]]; |
| 35 | 33 |
| 36 /// Add the two arguments with automatic type conversion. | 34 /// Add the two arguments with automatic type conversion. |
| 37 autoConvertAdd(a, b) { | 35 autoConvertAdd(a, b) { |
| 38 if (a != null && b != null) { | 36 if (a != null && b != null) { |
| 39 // TODO(deboer): Support others. | 37 // TODO(deboer): Support others. |
| 40 if (a is String && b is! String) { | 38 if (a is String && b is! String) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 } | 70 } |
| 73 | 71 |
| 74 /// Get a keyed element from the given [object]. | 72 /// Get a keyed element from the given [object]. |
| 75 getKeyed(object, key) { | 73 getKeyed(object, key) { |
| 76 if (object is List) { | 74 if (object is List) { |
| 77 return object[key.toInt()]; | 75 return object[key.toInt()]; |
| 78 } else if (object is Map) { | 76 } else if (object is Map) { |
| 79 return object["$key"]; // toString dangerous? | 77 return object["$key"]; // toString dangerous? |
| 80 } else if (object == null) { | 78 } else if (object == null) { |
| 81 throw new EvalError('Accessing null object'); | 79 throw new EvalError('Accessing null object'); |
| 82 } else { | |
| 83 return object[key]; | |
| 84 } | 80 } |
| 81 throw new EvalError("Attempted field access on a non-list, non-map"); |
| 85 } | 82 } |
| 86 | 83 |
| 87 /// Set a keyed element in the given [object]. | 84 /// Set a keyed element in the given [object]. |
| 88 setKeyed(object, key, value) { | 85 setKeyed(object, key, value) { |
| 89 if (object is List) { | 86 if (object is List) { |
| 90 int index = key.toInt(); | 87 int index = key.toInt(); |
| 91 if (object.length <= index) object.length = index + 1; | 88 if (object.length <= index) object.length = index + 1; |
| 92 object[index] = value; | 89 object[index] = value; |
| 93 } else if (object is Map) { | 90 } else if (object is Map) { |
| 94 object["$key"] = value; // toString dangerous? | 91 object["$key"] = value; // toString dangerous? |
| 95 } else { | 92 } else { |
| 96 object[key] = value; | 93 throw new EvalError("Attempting to set a field on a non-list, non-map"); |
| 97 } | 94 } |
| 98 return value; | 95 return value; |
| 99 } | 96 } |
| 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 |