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

Commit d9763f1

Browse files
lgalfasopetebacondarwin
authored andcommitted
fix($parse): handle constants as one-time binding expressions
Handle constant expressions as one-time binding expressions. Avoids the infinite digest from https://github.com/angular/angular.js/pull/7960/files#r14136938 Closes #7970
1 parent 91754a7 commit d9763f1

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/ng/parse.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -1027,11 +1027,7 @@ function $ParseProvider() {
10271027
cache[exp] = parsedExpression;
10281028
}
10291029

1030-
if (parsedExpression.constant) {
1031-
parsedExpression.$$unwatch = true;
1032-
}
1033-
1034-
return oneTime ? oneTimeWrapper(parsedExpression) : parsedExpression;
1030+
return oneTime || parsedExpression.constant ? oneTimeWrapper(parsedExpression) : parsedExpression;
10351031

10361032
case 'function':
10371033
return exp;
@@ -1050,7 +1046,7 @@ function $ParseProvider() {
10501046

10511047
function oneTimeParseFn(self, locals) {
10521048
if (!stable) {
1053-
lastValue = expression(self, locals);
1049+
lastValue = expression.constant && lastValue ? lastValue : expression(self, locals);
10541050
oneTimeParseFn.$$unwatch = isDefined(lastValue);
10551051
if (oneTimeParseFn.$$unwatch && self && self.$$postDigestQueue) {
10561052
self.$$postDigestQueue.push(function () {

test/ng/rootScopeSpec.js

+9
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,15 @@ describe('Scope', function() {
114114
expect($rootScope.$$watchers.length).toEqual(0);
115115
}));
116116

117+
it('should not keep constant literals on the watch queue', inject(function($rootScope) {
118+
$rootScope.$watch('[]', function() {});
119+
$rootScope.$watch('{}', function() {});
120+
expect($rootScope.$$watchers.length).toEqual(2);
121+
$rootScope.$digest();
122+
123+
expect($rootScope.$$watchers.length).toEqual(0);
124+
}));
125+
117126
it('should clean up stable watches on the watch queue', inject(function($rootScope, $parse) {
118127
$rootScope.$watch($parse('::foo'), function() {});
119128
expect($rootScope.$$watchers.length).toEqual(1);

0 commit comments

Comments
 (0)