Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 5e418b1

Browse files
kindygkalpak
authored andcommitted
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
1 parent f4bb973 commit 5e418b1

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/ng/parse.js

+7
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,13 @@ function findConstantAndWatchExpressions(ast, $filter) {
717717
if (!property.value.constant) {
718718
argsToWatch.push.apply(argsToWatch, property.value.toWatch);
719719
}
720+
if (property.computed) {
721+
findConstantAndWatchExpressions(property.key, $filter);
722+
if (!property.key.constant) {
723+
argsToWatch.push.apply(argsToWatch, property.key.toWatch);
724+
}
725+
}
726+
720727
});
721728
ast.constant = allConstants;
722729
ast.toWatch = argsToWatch;

test/ng/parseSpec.js

+33
Original file line numberDiff line numberDiff line change
@@ -3119,6 +3119,39 @@ describe('parser', function() {
31193119
expect(objB.value).toBe(scope.input);
31203120
}));
31213121

3122+
it('should watch ES6 object computed property changes', function() {
3123+
var count = 0;
3124+
var values = [];
3125+
3126+
scope.$watch('{[a]: true}', function(val) {
3127+
count++;
3128+
values.push(val);
3129+
}, true);
3130+
3131+
scope.$digest();
3132+
expect(count).toBe(1);
3133+
expect(values[0]).toEqual({'undefined': true});
3134+
3135+
scope.$digest();
3136+
expect(count).toBe(1);
3137+
expect(values[0]).toEqual({'undefined': true});
3138+
3139+
scope.a = true;
3140+
scope.$digest();
3141+
expect(count).toBe(2);
3142+
expect(values[1]).toEqual({'true': true});
3143+
3144+
scope.a = 'abc';
3145+
scope.$digest();
3146+
expect(count).toBe(3);
3147+
expect(values[2]).toEqual({'abc': true});
3148+
3149+
scope.a = undefined;
3150+
scope.$digest();
3151+
expect(count).toBe(4);
3152+
expect(values[3]).toEqual({'undefined': true});
3153+
});
3154+
31223155
it('should support watching literals', inject(function($parse) {
31233156
var lastVal = NaN;
31243157
var callCount = 0;

0 commit comments

Comments
 (0)