From 5a59e41572cc6b291b5fcc775e10ddd1d6548694 Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Wed, 6 Aug 2014 22:08:16 +0100 Subject: [PATCH] fix($parse): ternary should give assignment precedence in middle and right expressions 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..a43353fef3f3 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.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 27994bd0881c..a0cfa1f407bc 100644 --- a/test/ng/parseSpec.js +++ b/test/ng/parseSpec.js @@ -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() {