| Index: third_party/pkg/angular/lib/core/parser/static_parser.dart
|
| diff --git a/third_party/pkg/angular/lib/core/parser/static_parser.dart b/third_party/pkg/angular/lib/core/parser/static_parser.dart
|
| index 5d0db008c4aa1276822ab7728eb3cb2b931e7e72..155472108e3b83fe4354969cb838df05ad1730e3 100644
|
| --- a/third_party/pkg/angular/lib/core/parser/static_parser.dart
|
| +++ b/third_party/pkg/angular/lib/core/parser/static_parser.dart
|
| @@ -1,32 +1,59 @@
|
| -part of angular.core.parser;
|
| +library angular.core.parser.static_parser;
|
|
|
| -class StaticParserFunctions {
|
| - StaticParserFunctions(Map this.functions);
|
| +import 'package:angular/core/parser/parser.dart';
|
| +import 'package:angular/core/parser/utils.dart' show EvalError;
|
|
|
| - Map<String, dynamic> functions;
|
| +class StaticParserFunctions {
|
| + final Map<String, Function> eval;
|
| + final Map<String, Function> assign;
|
| + StaticParserFunctions(this.eval, this.assign);
|
| }
|
|
|
| -@NgInjectableService()
|
| -class StaticParser implements Parser {
|
| - Map<String, dynamic> _functions;
|
| - Parser _fallbackParser;
|
| +//@NgInjectableService()
|
| +class StaticParser implements Parser<Expression> {
|
| + final StaticParserFunctions _functions;
|
| + final DynamicParser _fallbackParser;
|
| + final Map<String, Expression> _cache = {};
|
| + StaticParser(this._functions, this._fallbackParser);
|
|
|
| - StaticParser(StaticParserFunctions functions,
|
| - DynamicParser this._fallbackParser) {
|
| - assert(functions != null);
|
| - _functions = functions.functions;
|
| + Expression call(String input) {
|
| + if (input == null) input = '';
|
| + return _cache.putIfAbsent(input, () => _construct(input));
|
| }
|
|
|
| - call(String exp) {
|
| - if (exp == null) exp = "";
|
| - if (!_functions.containsKey(exp)) {
|
| - //print("Expression [$exp] is not supported in static parser");
|
| - return _fallbackParser.call(exp);
|
| + Expression _construct(String input) {
|
| + var eval = _functions.eval[input];
|
| + if (eval == null) return _fallbackParser(input);
|
| + if (eval is !Function) throw eval;
|
| + Function assign = _functions.assign[input];
|
| + return new StaticExpression(input, eval, assign);
|
| + }
|
| +}
|
| +
|
| +class StaticExpression extends Expression {
|
| + final String _input;
|
| + final Function _eval;
|
| + final Function _assign;
|
| + StaticExpression(this._input, this._eval, [this._assign]);
|
| +
|
| + bool get isAssignable => _assign != null;
|
| + accept(Visitor visitor) => throw "Cannot visit static expression $this";
|
| + toString() => _input;
|
| +
|
| + eval(scope) {
|
| + try {
|
| + return _eval(scope);
|
| + } on EvalError catch (e, s) {
|
| + throw e.unwrap("$this", s);
|
| }
|
| - return _functions[exp];
|
| }
|
|
|
| - primaryFromToken(Token token, parserError) {
|
| - throw 'Not Implemented';
|
| + assign(scope, value) {
|
| + try {
|
| + if (_assign == null) throw new EvalError("Cannot assign to $this");
|
| + return _assign(scope, value);
|
| + } on EvalError catch (e, s) {
|
| + throw e.unwrap("$this", s);
|
| + }
|
| }
|
| -}
|
| +}
|
|
|