mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-01-12 22:45:52 +08:00
fix(parse): fix operators associativity
Make the operators `&&`, `==`, `!=`, `===`, `!==`, `<`, `>`, `<=`, `>=` follow Javascript left-to-right associativity
This commit is contained in:
@@ -598,8 +598,8 @@ Parser.prototype = {
|
||||
logicalAND: function() {
|
||||
var left = this.equality();
|
||||
var token;
|
||||
if ((token = this.expect('&&'))) {
|
||||
left = this.binaryFn(left, token.text, this.logicalAND(), true);
|
||||
while ((token = this.expect('&&'))) {
|
||||
left = this.binaryFn(left, token.text, this.equality(), true);
|
||||
}
|
||||
return left;
|
||||
},
|
||||
@@ -607,8 +607,8 @@ Parser.prototype = {
|
||||
equality: function() {
|
||||
var left = this.relational();
|
||||
var token;
|
||||
if ((token = this.expect('==','!=','===','!=='))) {
|
||||
left = this.binaryFn(left, token.text, this.equality());
|
||||
while ((token = this.expect('==','!=','===','!=='))) {
|
||||
left = this.binaryFn(left, token.text, this.relational());
|
||||
}
|
||||
return left;
|
||||
},
|
||||
@@ -616,8 +616,8 @@ Parser.prototype = {
|
||||
relational: function() {
|
||||
var left = this.additive();
|
||||
var token;
|
||||
if ((token = this.expect('<', '>', '<=', '>='))) {
|
||||
left = this.binaryFn(left, token.text, this.relational());
|
||||
while ((token = this.expect('<', '>', '<=', '>='))) {
|
||||
left = this.binaryFn(left, token.text, this.additive());
|
||||
}
|
||||
return left;
|
||||
},
|
||||
|
||||
@@ -276,6 +276,10 @@ describe('parser', function() {
|
||||
expect(scope.$eval("2>=1")).toEqual(2 >= 1);
|
||||
expect(scope.$eval("true==2<3")).toEqual(true == 2 < 3);
|
||||
expect(scope.$eval("true===2<3")).toEqual(true === 2 < 3);
|
||||
|
||||
expect(scope.$eval("true===3===3")).toEqual(true === 3 === 3);
|
||||
expect(scope.$eval("3===3===true")).toEqual(3 === 3 === true);
|
||||
expect(scope.$eval("3 >= 3 > 2")).toEqual(3 >= 3 > 2);
|
||||
});
|
||||
|
||||
it('should parse logical', function() {
|
||||
@@ -703,6 +707,7 @@ describe('parser', function() {
|
||||
throw "IT SHOULD NOT HAVE RUN";
|
||||
};
|
||||
expect(scope.$eval('false && run()')).toBe(false);
|
||||
expect(scope.$eval('false && true && run()')).toBe(false);
|
||||
});
|
||||
|
||||
it('should short-circuit OR operator', function() {
|
||||
@@ -710,6 +715,7 @@ describe('parser', function() {
|
||||
throw "IT SHOULD NOT HAVE RUN";
|
||||
};
|
||||
expect(scope.$eval('true || run()')).toBe(true);
|
||||
expect(scope.$eval('true || false || run()')).toBe(true);
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user