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

Commit

Permalink
fix($parse): mark constant unary minus expressions as constant
Browse files Browse the repository at this point in the history
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
  • Loading branch information
teropa authored and caitp committed Apr 2, 2014
1 parent 10110bc commit 7914d34
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/ng/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions test/ng/parseSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 7914d34

Please sign in to comment.