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:
committed by
Georgios Kalpakas
parent
15581287a4
commit
8162362217
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user