fix($parse): make sure ES6 object computed properties are watched

Add the missing watches for ES6 object computed properties which were
implemented in #14407.

Closes #15678
This commit is contained in:
Kindy Lin
2017-01-24 15:54:53 +08:00
committed by Georgios Kalpakas
parent 15581287a4
commit 8162362217
2 changed files with 40 additions and 0 deletions
+7
View File
@@ -717,6 +717,13 @@ function findConstantAndWatchExpressions(ast, $filter) {
if (!property.value.constant) {
argsToWatch.push.apply(argsToWatch, property.value.toWatch);
}
if (property.computed) {
findConstantAndWatchExpressions(property.key, $filter);
if (!property.key.constant) {
argsToWatch.push.apply(argsToWatch, property.key.toWatch);
}
}
});
ast.constant = allConstants;
ast.toWatch = argsToWatch;
+33
View File
@@ -3119,6 +3119,39 @@ describe('parser', function() {
expect(objB.value).toBe(scope.input);
}));
it('should watch ES6 object computed property changes', function() {
var count = 0;
var values = [];
scope.$watch('{[a]: true}', function(val) {
count++;
values.push(val);
}, true);
scope.$digest();
expect(count).toBe(1);
expect(values[0]).toEqual({'undefined': true});
scope.$digest();
expect(count).toBe(1);
expect(values[0]).toEqual({'undefined': true});
scope.a = true;
scope.$digest();
expect(count).toBe(2);
expect(values[1]).toEqual({'true': true});
scope.a = 'abc';
scope.$digest();
expect(count).toBe(3);
expect(values[2]).toEqual({'abc': true});
scope.a = undefined;
scope.$digest();
expect(count).toBe(4);
expect(values[3]).toEqual({'undefined': true});
});
it('should support watching literals', inject(function($parse) {
var lastVal = NaN;
var callCount = 0;