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

Commit 6e420ff

Browse files
teropacaitp
authored andcommitted
fix($parse): mark constant unary minus expressions as constant
Previously, constant numbers with a unary minus sign were not treated as constants. This fix corrects this behaviour, and may provide a small performance boost for certain applications, due to constant watches being automatically unregistered after their first listener call. Closes #6932
1 parent 5393814 commit 6e420ff

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/ng/parse.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,11 @@ var Parser = function (lexer, $filter, options) {
393393
this.options = options;
394394
};
395395

396-
Parser.ZERO = function () { return 0; };
396+
Parser.ZERO = extend(function () {
397+
return 0;
398+
}, {
399+
constant: true
400+
});
397401

398402
Parser.prototype = {
399403
constructor: Parser,

test/ng/parseSpec.js

+1
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,7 @@ describe('parser', function() {
10311031

10321032
it('should mark complex expressions involving constant values as constant', inject(function($parse) {
10331033
expect($parse('!true').constant).toBe(true);
1034+
expect($parse('-42').constant).toBe(true);
10341035
expect($parse('1 - 1').constant).toBe(true);
10351036
expect($parse('"foo" + "bar"').constant).toBe(true);
10361037
expect($parse('5 != null').constant).toBe(true);

0 commit comments

Comments
 (0)