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

Commit 8de9794

Browse files
committedJul 18, 2017
fix($parse): support constants in computed keys
1 parent 2fb2d09 commit 8de9794

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed
 

‎src/ng/parse.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -745,12 +745,13 @@ function findConstantAndWatchExpressions(ast, $filter, parentIsPure) {
745745
argsToWatch = [];
746746
forEach(ast.properties, function(property) {
747747
findConstantAndWatchExpressions(property.value, $filter, astIsPure);
748-
allConstants = allConstants && property.value.constant && !property.computed;
748+
allConstants = allConstants && property.value.constant;
749749
if (!property.value.constant) {
750750
argsToWatch.push.apply(argsToWatch, property.value.toWatch);
751751
}
752752
if (property.computed) {
753753
findConstantAndWatchExpressions(property.key, $filter, astIsPure);
754+
allConstants = allConstants && property.key.constant;
754755
if (!property.key.constant) {
755756
argsToWatch.push.apply(argsToWatch, property.key.toWatch);
756757
}

‎test/ng/parseSpec.js

+5
Original file line numberDiff line numberDiff line change
@@ -4009,6 +4009,11 @@ describe('parser', function() {
40094009
expect($parse('5 != null').constant).toBe(true);
40104010
expect($parse('{standard: 4/3, wide: 16/9}').constant).toBe(true);
40114011
expect($parse('{[standard]: 4/3, wide: 16/9}').constant).toBe(false);
4012+
expect($parse('{["key"]: 1}').constant).toBe(true);
4013+
expect($parse('[0].length').constant).toBe(true);
4014+
expect($parse('[0][0]').constant).toBe(true);
4015+
expect($parse('{x: 1}.x').constant).toBe(true);
4016+
expect($parse('{x: 1}["x"]').constant).toBe(true);
40124017
}));
40134018

40144019
it('should not mark any expression involving variables or function calls as constant', inject(function($parse) {

0 commit comments

Comments
 (0)
This repository has been archived.