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

fix($parse): ternary and assignment operator precedence #8516

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.filterChain();
if ((token = this.expect(':'))) {
return this.ternaryFn(left, middle, this.ternary());
return this.ternaryFn(left, middle, this.filterChain());
} 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 @@ -265,6 +265,7 @@ describe('parser', function() {
var returnString = scope.returnString = function(){ return 'asd'; };
var returnInt = scope.returnInt = function(){ return 123; };
var identity = scope.identity = function(x){ return x; };
var foo;

// Simple.
expect(scope.$eval('0?0:2')).toEqual(0?0:2);
Expand Down Expand Up @@ -316,6 +317,9 @@ describe('parser', function() {
expect(scope.$eval('1?1:0||0')).toEqual(1?1:0||0);
expect(scope.$eval('1?2:0||1')).toEqual(1?2:0||1);

// Precedence with respect to assignmets
expect(scope.$eval('1?foo=true:foo=false')).toEqual(1?foo=true:foo=false);

// Function calls.
expect(scope.$eval('returnTrue() ? returnString() : returnInt()')).toEqual(returnTrue() ? returnString() : returnInt());
expect(scope.$eval('returnFalse() ? returnString() : returnInt()')).toEqual(returnFalse() ? returnString() : returnInt());
Expand Down