@@ -3070,6 +3070,29 @@ describe('parser', function() {
3070
3070
expect ( watcherCalls ) . toBe ( 2 ) ;
3071
3071
} ) ) ;
3072
3072
3073
+ it ( 'should not reevaluate filters within literals with primitive inputs' , inject ( function ( $parse ) {
3074
+ var filterCalls = 0 ;
3075
+ $filterProvider . register ( 'foo' , valueFn ( function ( input ) {
3076
+ filterCalls ++ ;
3077
+ return input ;
3078
+ } ) ) ;
3079
+
3080
+ scope . prim = 1234567890123 ;
3081
+
3082
+ var watcherCalls = 0 ;
3083
+ scope . $watch ( '[(prim | foo)]' , function ( input ) {
3084
+ watcherCalls ++ ;
3085
+ } ) ;
3086
+
3087
+ scope . $digest ( ) ;
3088
+ expect ( filterCalls ) . toBe ( 1 ) ;
3089
+ expect ( watcherCalls ) . toBe ( 1 ) ;
3090
+
3091
+ scope . $digest ( ) ;
3092
+ expect ( filterCalls ) . toBe ( 1 ) ;
3093
+ expect ( watcherCalls ) . toBe ( 1 ) ;
3094
+ } ) ) ;
3095
+
3073
3096
it ( 'should always reevaluate filters with non-primitive inputs within literals' ,
3074
3097
inject ( function ( $parse ) {
3075
3098
$filterProvider . register ( 'foo' , valueFn ( function ( input ) {
@@ -3078,7 +3101,7 @@ describe('parser', function() {
3078
3101
3079
3102
scope . $watch ( '[(a | foo)]' , function ( ) { } ) ;
3080
3103
3081
- // Would be great if this didn't throw...
3104
+ // Would be great if filter-output was checked for changes and this didn't throw...
3082
3105
expect ( function ( ) { scope . $apply ( 'a = {b: 1}' ) ; } ) . toThrowMinErr ( '$rootScope' , 'infdig' ) ;
3083
3106
} ) ) ;
3084
3107
@@ -3088,7 +3111,7 @@ describe('parser', function() {
3088
3111
3089
3112
scope . $apply ( 'a = 1' ) ;
3090
3113
3091
- // Would be great if this didn't throw...
3114
+ // Would be great if filter-output was checked for changes and this didn't throw...
3092
3115
expect ( function ( ) { scope . $apply ( 'a = {}' ) ; } ) . toThrowMinErr ( '$rootScope' , 'infdig' ) ;
3093
3116
} ) ) ;
3094
3117
@@ -3116,6 +3139,30 @@ describe('parser', function() {
3116
3139
expect ( watcherCalls ) . toBe ( 1 ) ;
3117
3140
} ) ) ;
3118
3141
3142
+ it ( 'should not reevaluate filters with non-primitive input that gets simplified via non plus/concat binary operators' ,
3143
+ inject ( function ( $parse ) {
3144
+ var filterCalls = 0 ;
3145
+ $filterProvider . register ( 'foo' , valueFn ( function ( input ) {
3146
+ filterCalls ++ ;
3147
+ return input ;
3148
+ } ) ) ;
3149
+
3150
+ scope . obj = { } ;
3151
+
3152
+ var watcherCalls = 0 ;
3153
+ scope . $watch ( '1 - obj | foo:(1 * obj)' , function ( input ) {
3154
+ watcherCalls ++ ;
3155
+ } ) ;
3156
+
3157
+ scope . $digest ( ) ;
3158
+ expect ( filterCalls ) . toBe ( 1 ) ;
3159
+ expect ( watcherCalls ) . toBe ( 1 ) ;
3160
+
3161
+ scope . $digest ( ) ;
3162
+ expect ( filterCalls ) . toBe ( 1 ) ;
3163
+ expect ( watcherCalls ) . toBe ( 1 ) ;
3164
+ } ) ) ;
3165
+
3119
3166
it ( 'should reevaluate filters with non-primitive input that gets simplified via plus/concat' , inject ( function ( $parse ) {
3120
3167
var filterCalls = 0 ;
3121
3168
$filterProvider . register ( 'foo' , valueFn ( function ( input ) {
@@ -3139,6 +3186,31 @@ describe('parser', function() {
3139
3186
expect ( watcherCalls ) . toBe ( 1 ) ;
3140
3187
} ) ) ;
3141
3188
3189
+ it ( 'should reevaluate computed member expressions with non-primitive input' , inject ( function ( $parse ) {
3190
+ var toStringCalls = 0 ;
3191
+
3192
+ scope . obj = { } ;
3193
+ scope . key = {
3194
+ toString : function ( ) {
3195
+ toStringCalls ++ ;
3196
+ return 'foo' ;
3197
+ }
3198
+ } ;
3199
+
3200
+ var watcherCalls = 0 ;
3201
+ scope . $watch ( 'obj[key]' , function ( input ) {
3202
+ watcherCalls ++ ;
3203
+ } ) ;
3204
+
3205
+ scope . $digest ( ) ;
3206
+ expect ( toStringCalls ) . toBe ( 2 ) ;
3207
+ expect ( watcherCalls ) . toBe ( 1 ) ;
3208
+
3209
+ scope . $digest ( ) ;
3210
+ expect ( toStringCalls ) . toBe ( 3 ) ;
3211
+ expect ( watcherCalls ) . toBe ( 1 ) ;
3212
+ } ) ) ;
3213
+
3142
3214
it ( 'should always reevaluate filters with non-primitive input created with null prototype' ,
3143
3215
inject ( function ( $parse ) {
3144
3216
var filterCalls = 0 ;
@@ -3244,6 +3316,23 @@ describe('parser', function() {
3244
3316
expect ( called ) . toBe ( true ) ;
3245
3317
} ) ) ;
3246
3318
3319
+ it ( 'should not reevaluate literals with non-primitive input' , inject ( function ( $parse ) {
3320
+ var obj = scope . obj = { } ;
3321
+
3322
+ var parsed = $parse ( '[obj]' ) ;
3323
+ var watcherCalls = 0 ;
3324
+ scope . $watch ( parsed , function ( input ) {
3325
+ expect ( input [ 0 ] ) . toBe ( obj ) ;
3326
+ watcherCalls ++ ;
3327
+ } ) ;
3328
+
3329
+ scope . $digest ( ) ;
3330
+ expect ( watcherCalls ) . toBe ( 1 ) ;
3331
+
3332
+ scope . $digest ( ) ;
3333
+ expect ( watcherCalls ) . toBe ( 1 ) ;
3334
+ } ) ) ;
3335
+
3247
3336
it ( 'should not reevaluate literals with non-primitive input that does support valueOf()' ,
3248
3337
inject ( function ( $parse ) {
3249
3338
@@ -3263,6 +3352,25 @@ describe('parser', function() {
3263
3352
expect ( watcherCalls ) . toBe ( 1 ) ;
3264
3353
} ) ) ;
3265
3354
3355
+ it ( 'should reevaluate literals with non-primitive input when valueOf() changes' , inject ( function ( $parse ) {
3356
+ var date = scope . date = new Date ( ) ;
3357
+
3358
+ var parsed = $parse ( '[date]' ) ;
3359
+ var watcherCalls = 0 ;
3360
+ scope . $watch ( parsed , function ( input ) {
3361
+ expect ( input [ 0 ] ) . toBe ( date ) ;
3362
+ watcherCalls ++ ;
3363
+ } ) ;
3364
+
3365
+ scope . $digest ( ) ;
3366
+ expect ( watcherCalls ) . toBe ( 1 ) ;
3367
+
3368
+ date . setYear ( 1901 ) ;
3369
+
3370
+ scope . $digest ( ) ;
3371
+ expect ( watcherCalls ) . toBe ( 2 ) ;
3372
+ } ) ) ;
3373
+
3266
3374
it ( 'should not reevaluate literals with non-primitive input that does support valueOf()' +
3267
3375
' when the instance changes but valueOf() does not' , inject ( function ( $parse ) {
3268
3376
0 commit comments