Chromium Code Reviews| Index: pkg/polymer_expressions/lib/eval.dart |
| diff --git a/pkg/polymer_expressions/lib/eval.dart b/pkg/polymer_expressions/lib/eval.dart |
| index 2332cf908f6f276aea268197cba996be800abaa3..4a2ee419ed23065ae5c82abe690ad940dcb9ea57 100644 |
| --- a/pkg/polymer_expressions/lib/eval.dart |
| +++ b/pkg/polymer_expressions/lib/eval.dart |
| @@ -60,7 +60,7 @@ Object eval(Expression expr, Scope scope) { |
| * [ExpressionObsserver]. |
| */ |
| ExpressionObserver observe(Expression expr, Scope scope) { |
| - var observer = new ObserverBuilder(scope).visit(expr); |
| + var observer = new ObserverBuilder().visit(expr); |
| return observer; |
| } |
| @@ -151,6 +151,9 @@ void assign(Expression expr, Object value, Scope scope) { |
| * and then finally looks up the name as a property in the model. |
| */ |
| abstract class Scope implements Indexable<String, Object> { |
| + static int __seq = 1; |
| + final int _seq = __seq++; |
| + |
| Scope._(); |
| /** Create a scope containing a [model] and all of [variables]. */ |
| @@ -184,6 +187,9 @@ abstract class Scope implements Indexable<String, Object> { |
| /** Create a new scope extending this scope with an additional variable. */ |
| Scope childScope(String name, Object value) => |
| new _LocalVariableScope(name, value, this); |
| + |
| + String toString() => 'Scope(seq: $_seq model: $model)'; |
| + |
| } |
| /** |
| @@ -207,6 +213,8 @@ class _ModelScope extends Scope { |
| } |
| Object _isModelProperty(String name) => name != 'this'; |
| + |
| + String toString() => 'ModelScope(model: $model)'; |
| } |
| /** |
| @@ -238,6 +246,8 @@ class _LocalVariableScope extends Scope { |
| if (varName == name) return false; |
| return parent == null ? false : parent._isModelProperty(name); |
| } |
| + |
| + String toString() => 'LocalVariableScope(varName: $varName, value: $value, parent: $parent)'; |
|
Jennifer Messerly
2014/04/24 00:51:34
long line
justinfagnani
2014/05/28 00:29:37
Done.
|
| } |
| /** A scope that holds a reference to a global variables. */ |
| @@ -263,6 +273,8 @@ class _GlobalsScope extends Scope { |
| if (variables.containsKey(name)) return false; |
| return parent == null ? false : parent._isModelProperty(name); |
| } |
| + |
| + String toString() => 'GlobalsScope(variables: $variables, parent: $parent)'; |
| } |
| Object _convert(v) => v is Stream ? new StreamBinding(v) : v; |
| @@ -322,18 +334,12 @@ class Updater extends RecursiveVisitor { |
| visitExpression(ExpressionObserver e) { |
| e._observe(scope); |
| } |
| - |
| - visitInExpression(InObserver c) { |
| - visit(c.right); |
| - visitExpression(c); |
| - } |
| } |
| class ObserverBuilder extends Visitor { |
| - final Scope scope; |
| final Queue parents = new Queue(); |
| - ObserverBuilder(this.scope); |
| + ObserverBuilder(); |
| visitEmptyExpression(EmptyExpression e) => new EmptyObserver(e); |
| @@ -421,13 +427,11 @@ class ObserverBuilder extends Visitor { |
| } |
| visitInExpression(InExpression i) { |
| - // don't visit the left. It's an identifier, but we don't want to evaluate |
| - // it, we just want to add it to the comprehension object |
| - var left = visit(i.left); |
| - var right = visit(i.right); |
| - var inexpr = new InObserver(i, left, right); |
| - right._parent = inexpr; |
| - return inexpr; |
| + throw new UnsupportedError("can't eval an 'in' expression"); |
| + } |
| + |
| + visitAsExpression(AsExpression i) { |
| + throw new UnsupportedError("can't eval an 'as' expression"); |
| } |
| } |
| @@ -705,47 +709,9 @@ class InvokeObserver extends ExpressionObserver<Invoke> implements Invoke { |
| accept(Visitor v) => v.visitInvoke(this); |
| } |
| -class InObserver extends ExpressionObserver<InExpression> |
| - implements InExpression { |
| - IdentifierObserver left; |
| - ExpressionObserver right; |
| - |
| - InObserver(Expression expr, this.left, this.right) : super(expr); |
| - |
| - _updateSelf(Scope scope) { |
| - Identifier identifier = left; |
| - var iterable = right._value; |
| - |
| - if (iterable is! Iterable && iterable != null) { |
| - throw new EvalException("right side of 'in' is not an iterator"); |
| - } |
| - |
| - if (iterable is ObservableList) { |
| - _subscription = iterable.listChanges.listen((_) => _invalidate(scope)); |
| - } |
| - |
| - // TODO: make Comprehension observable and update it |
| - _value = new Comprehension(identifier.value, iterable); |
| - } |
| - |
| - accept(Visitor v) => v.visitInExpression(this); |
| -} |
| _toBool(v) => (v == null) ? false : v; |
| -/** |
| - * A comprehension declaration ("a in b"). [identifier] is the loop variable |
| - * that's added to the scope during iteration. [iterable] is the set of |
| - * objects to iterate over. |
| - */ |
| -class Comprehension { |
| - final String identifier; |
| - final Iterable iterable; |
| - |
| - Comprehension(this.identifier, Iterable iterable) |
| - : iterable = (iterable != null) ? iterable : const []; |
| -} |
| - |
| class EvalException implements Exception { |
| final String message; |
| EvalException(this.message); |