From bba766be09d649993f9b7c625f93f4fb2b64b807 Mon Sep 17 00:00:00 2001 From: Lucas Galfaso Date: Thu, 7 Aug 2014 00:03:52 +0200 Subject: [PATCH] fix($parse): ternary and assignment operator precedence Properly handle assignemnts inside ternary operators Closes #8484 --- src/ng/parse.js | 4 ++-- test/ng/parseSpec.js | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ng/parse.js b/src/ng/parse.js index 11cf501d9f83..7ab41c563b41 100644 --- a/src/ng/parse.js +++ b/src/ng/parse.js @@ -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); } diff --git a/test/ng/parseSpec.js b/test/ng/parseSpec.js index 27994bd0881c..83b5485288c0 100644 --- a/test/ng/parseSpec.js +++ b/test/ng/parseSpec.js @@ -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); @@ -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());