fix($parse): support constants in computed keys

This commit is contained in:
Jason Bedard
2017-07-16 22:13:44 -07:00
parent 2fb2d09971
commit 8de97949c5
2 changed files with 7 additions and 1 deletions
+2 -1
View File
@@ -745,12 +745,13 @@ function findConstantAndWatchExpressions(ast, $filter, parentIsPure) {
argsToWatch = [];
forEach(ast.properties, function(property) {
findConstantAndWatchExpressions(property.value, $filter, astIsPure);
allConstants = allConstants && property.value.constant && !property.computed;
allConstants = allConstants && property.value.constant;
if (!property.value.constant) {
argsToWatch.push.apply(argsToWatch, property.value.toWatch);
}
if (property.computed) {
findConstantAndWatchExpressions(property.key, $filter, astIsPure);
allConstants = allConstants && property.key.constant;
if (!property.key.constant) {
argsToWatch.push.apply(argsToWatch, property.key.toWatch);
}
+5
View File
@@ -4009,6 +4009,11 @@ describe('parser', function() {
expect($parse('5 != null').constant).toBe(true);
expect($parse('{standard: 4/3, wide: 16/9}').constant).toBe(true);
expect($parse('{[standard]: 4/3, wide: 16/9}').constant).toBe(false);
expect($parse('{["key"]: 1}').constant).toBe(true);
expect($parse('[0].length').constant).toBe(true);
expect($parse('[0][0]').constant).toBe(true);
expect($parse('{x: 1}.x').constant).toBe(true);
expect($parse('{x: 1}["x"]').constant).toBe(true);
}));
it('should not mark any expression involving variables or function calls as constant', inject(function($parse) {