Skip to content

Commit

Permalink
fix($parse): ternary should give assignment precedence in middle and …
Browse files Browse the repository at this point in the history
…right expressions

Closes angular#8484
  • Loading branch information
petebacondarwin committed Aug 6, 2014
1 parent fcd76d2 commit 5a59e41
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/ng/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -589,9 +589,9 @@ Parser.prototype = {
var middle;
var token;
if ((token = this.expect('?'))) {
middle = this.ternary();
middle = this.assignment();
if ((token = this.expect(':'))) {
return this.ternaryFn(left, middle, this.ternary());
return this.ternaryFn(left, middle, this.assignment());
} else {
this.throwError('expected :', token);
}
Expand Down
4 changes: 4 additions & 0 deletions test/ng/parseSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,10 @@ describe('parser', function() {
expect(scope.$eval('returnFalse() ? returnString() : returnInt()')).toEqual(returnFalse() ? returnString() : returnInt());
expect(scope.$eval('returnTrue() ? returnString() : returnInt()')).toEqual(returnTrue() ? returnString() : returnInt());
expect(scope.$eval('identity(returnFalse() ? returnString() : returnInt())')).toEqual(identity(returnFalse() ? returnString() : returnInt()));

// Assignment
expect(scope.$eval('false ? x=1 : x=2')).toEqual(2);
expect(scope.x).toEqual(2);
});

it('should parse string', function() {
Expand Down

0 comments on commit 5a59e41

Please sign in to comment.