mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-08 09:07:46 +08:00
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:
committed by
Caitlin Potter
parent
5393814756
commit
6e420ff28d
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user