Skip to content

Commit 4b8bbf8

Browse files
committed
fix($parse): Make sure ES6 object computed property to be watched
Adding the missing watches for ES6 object property which added in angular#14407
1 parent f73a651 commit 4b8bbf8

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/ng/parse.js

+7
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,13 @@ function findConstantAndWatchExpressions(ast, $filter) {
815815
if (!property.value.constant) {
816816
argsToWatch.push.apply(argsToWatch, property.value.toWatch);
817817
}
818+
if (property.computed) {
819+
findConstantAndWatchExpressions(property.key, $filter);
820+
if (!property.key.constant) {
821+
argsToWatch.push.apply(argsToWatch, property.key.toWatch);
822+
}
823+
}
824+
818825
});
819826
ast.constant = allConstants;
820827
ast.toWatch = argsToWatch;

test/ng/parseSpec.js

+35
Original file line numberDiff line numberDiff line change
@@ -3868,6 +3868,41 @@ describe('parser', function() {
38683868
scope.$digest();
38693869
expect(objB.value).toBe(scope.input);
38703870
}));
3871+
3872+
it('should watch ES6 object computed property changes', function() {
3873+
var count = 0;
3874+
var values = [];
3875+
var firstValue = {'undefined': true};
3876+
3877+
scope.$watch('{[a]: true}', function(val, oldVal) {
3878+
count++;
3879+
values.push(val);
3880+
}, true);
3881+
3882+
scope.$digest();
3883+
expect(count).toBe(1);
3884+
expect(values[0]).toEqual(firstValue);
3885+
3886+
scope.$digest();
3887+
expect(count).toBe(1);
3888+
expect(values[0]).toEqual(firstValue);
3889+
3890+
scope.a = true;
3891+
scope.$digest();
3892+
expect(count).toBe(2);
3893+
expect(values[1]).toEqual({'true': true});
3894+
3895+
scope.a = 'abc';
3896+
scope.$digest();
3897+
expect(count).toBe(3);
3898+
expect(values[2]).toEqual({'abc': true});
3899+
3900+
scope.a = undefined;
3901+
scope.$digest();
3902+
expect(count).toBe(4);
3903+
expect(values[3]).toEqual({'undefined': true});
3904+
});
3905+
38713906
});
38723907

38733908
describe('locals', function() {

0 commit comments

Comments
 (0)