feat($parse): allow for assignments in ternary operator branches

Closes #8512
Closes #8484
CLoses #5434

Conflicts:
	test/ng/parseSpec.js
This commit is contained in:
rodyhaddad
2013-12-16 13:02:25 -05:00
committed by Peter Bacon Darwin
parent d262378b7c
commit 93b0c2d892
2 changed files with 13 additions and 2 deletions
+2 -2
View File
@@ -606,9 +606,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);
}
+11
View File
@@ -434,6 +434,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);