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
This commit is contained in:
Tero Parviainen
2014-04-01 06:53:35 +03:00
committed by Caitlin Potter
parent 5393814756
commit 6e420ff28d
2 changed files with 6 additions and 1 deletions

View File

@@ -393,7 +393,11 @@ var Parser = function (lexer, $filter, options) {
this.options = options;
};
Parser.ZERO = function () { return 0; };
Parser.ZERO = extend(function () {
return 0;
}, {
constant: true
});
Parser.prototype = {
constructor: Parser,

View File

@@ -1031,6 +1031,7 @@ describe('parser', function() {
it('should mark complex expressions involving constant values as constant', inject(function($parse) {
expect($parse('!true').constant).toBe(true);
expect($parse('-42').constant).toBe(true);
expect($parse('1 - 1').constant).toBe(true);
expect($parse('"foo" + "bar"').constant).toBe(true);
expect($parse('5 != null').constant).toBe(true);