Skip to content

Commit 9d6c3f3

Browse files
committed
fix($parse): support constants in computed keys
1 parent ac0e260 commit 9d6c3f3

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/ng/parse.js

Lines changed: 2 additions & 1 deletion
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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3772,6 +3772,11 @@ describe('parser', function() {
37723772
expect($parse('5 != null').constant).toBe(true);
37733773
expect($parse('{standard: 4/3, wide: 16/9}').constant).toBe(true);
37743774
expect($parse('{[standard]: 4/3, wide: 16/9}').constant).toBe(false);
3775+
expect($parse('{["key"]: 1}').constant).toBe(true);
3776+
expect($parse('[0].length').constant).toBe(true);
3777+
expect($parse('[0][0]').constant).toBe(true);
3778+
expect($parse('{x: 1}.x').constant).toBe(true);
3779+
expect($parse('{x: 1}["x"]').constant).toBe(true);
37753780
}));
37763781

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

0 commit comments

Comments
 (0)