Skip to content

Commit 93b0c2d

Browse files
rodyhaddadpetebacondarwin
authored andcommitted
feat($parse): allow for assignments in ternary operator branches
Closes angular#8512 Closes angular#8484 CLoses angular#5434 Conflicts: test/ng/parseSpec.js
1 parent d262378 commit 93b0c2d

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/ng/parse.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,9 +606,9 @@ Parser.prototype = {
606606
var middle;
607607
var token;
608608
if ((token = this.expect('?'))) {
609-
middle = this.ternary();
609+
middle = this.assignment();
610610
if ((token = this.expect(':'))) {
611-
return this.ternaryFn(left, middle, this.ternary());
611+
return this.ternaryFn(left, middle, this.assignment());
612612
} else {
613613
this.throwError('expected :', token);
614614
}

test/ng/parseSpec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,17 @@ describe('parser', function() {
434434
expect(scope.b).toEqual(234);
435435
});
436436

437+
it('should evaluate assignments in ternary operator', function() {
438+
scope.$eval('a = 1 ? 2 : 3');
439+
expect(scope.a).toBe(2);
440+
441+
scope.$eval('0 ? a = 2 : a = 3');
442+
expect(scope.a).toBe(3);
443+
444+
scope.$eval('1 ? a = 2 : a = 3');
445+
expect(scope.a).toBe(2);
446+
});
447+
437448
it('should evaluate function call without arguments', function() {
438449
scope['const'] = function(a,b){return 123;};
439450
expect(scope.$eval("const()")).toEqual(123);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy