File tree 2 files changed +13
-2
lines changed
2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -606,9 +606,9 @@ Parser.prototype = {
606
606
var middle ;
607
607
var token ;
608
608
if ( ( token = this . expect ( '?' ) ) ) {
609
- middle = this . ternary ( ) ;
609
+ middle = this . assignment ( ) ;
610
610
if ( ( token = this . expect ( ':' ) ) ) {
611
- return this . ternaryFn ( left , middle , this . ternary ( ) ) ;
611
+ return this . ternaryFn ( left , middle , this . assignment ( ) ) ;
612
612
} else {
613
613
this . throwError ( 'expected :' , token ) ;
614
614
}
Original file line number Diff line number Diff line change @@ -434,6 +434,17 @@ describe('parser', function() {
434
434
expect ( scope . b ) . toEqual ( 234 ) ;
435
435
} ) ;
436
436
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
+
437
448
it ( 'should evaluate function call without arguments' , function ( ) {
438
449
scope [ 'const' ] = function ( a , b ) { return 123 ; } ;
439
450
expect ( scope . $eval ( "const()" ) ) . toEqual ( 123 ) ;
You can’t perform that action at this time.
0 commit comments