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:
committed by
Peter Bacon Darwin
parent
d262378b7c
commit
93b0c2d892
+2
-2
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user