From 5022e650033ec48e96448e22366d5503d05a9514 Mon Sep 17 00:00:00 2001 From: rodyhaddad Date: Mon, 16 Dec 2013 13:02:25 -0500 Subject: [PATCH] feat($parse): allow for assignments in ternary operator branches --- src/ng/parse.js | 4 ++-- test/ng/parseSpec.js | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/ng/parse.js b/src/ng/parse.js index 8b3f145a8211..99f9bc1f02f5 100644 --- a/src/ng/parse.js +++ b/src/ng/parse.js @@ -620,9 +620,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); } diff --git a/test/ng/parseSpec.js b/test/ng/parseSpec.js index 2147c4b0b0d1..ede03a373c84 100644 --- a/test/ng/parseSpec.js +++ b/test/ng/parseSpec.js @@ -398,6 +398,17 @@ describe('parser', function() { expect(scope.b).toEqual(234); }); + it('should evaluate assignments in ternary operator', function() { + scope.$eval('a = 1 ? 2 : 3'); + expect(scope.a).toBe(2); + + scope.$eval('0 ? a = 2 : a = 3'); + expect(scope.a).toBe(3); + + scope.$eval('1 ? a = 2 : a = 3'); + expect(scope.a).toBe(2); + }); + it('should evaluate function call without arguments', function() { scope['const'] = function(a,b){return 123;}; expect(scope.$eval("const()")).toEqual(123);