File tree 2 files changed +42
-0
lines changed
2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -815,6 +815,13 @@ function findConstantAndWatchExpressions(ast, $filter) {
815
815
if ( ! property . value . constant ) {
816
816
argsToWatch . push . apply ( argsToWatch , property . value . toWatch ) ;
817
817
}
818
+ if ( property . computed ) {
819
+ findConstantAndWatchExpressions ( property . key , $filter ) ;
820
+ if ( ! property . key . constant ) {
821
+ argsToWatch . push . apply ( argsToWatch , property . key . toWatch ) ;
822
+ }
823
+ }
824
+
818
825
} ) ;
819
826
ast . constant = allConstants ;
820
827
ast . toWatch = argsToWatch ;
Original file line number Diff line number Diff line change @@ -3868,6 +3868,41 @@ describe('parser', function() {
3868
3868
scope . $digest ( ) ;
3869
3869
expect ( objB . value ) . toBe ( scope . input ) ;
3870
3870
} ) ) ;
3871
+
3872
+ it ( 'should watch ES6 object computed property changes' , function ( ) {
3873
+ var count = 0 ;
3874
+ var values = [ ] ;
3875
+ var firstValue = { 'undefined' : true } ;
3876
+
3877
+ scope . $watch ( '{[a]: true}' , function ( val , oldVal ) {
3878
+ count ++ ;
3879
+ values . push ( val ) ;
3880
+ } , true ) ;
3881
+
3882
+ scope . $digest ( ) ;
3883
+ expect ( count ) . toBe ( 1 ) ;
3884
+ expect ( values [ 0 ] ) . toEqual ( firstValue ) ;
3885
+
3886
+ scope . $digest ( ) ;
3887
+ expect ( count ) . toBe ( 1 ) ;
3888
+ expect ( values [ 0 ] ) . toEqual ( firstValue ) ;
3889
+
3890
+ scope . a = true ;
3891
+ scope . $digest ( ) ;
3892
+ expect ( count ) . toBe ( 2 ) ;
3893
+ expect ( values [ 1 ] ) . toEqual ( { 'true' : true } ) ;
3894
+
3895
+ scope . a = 'abc' ;
3896
+ scope . $digest ( ) ;
3897
+ expect ( count ) . toBe ( 3 ) ;
3898
+ expect ( values [ 2 ] ) . toEqual ( { 'abc' : true } ) ;
3899
+
3900
+ scope . a = undefined ;
3901
+ scope . $digest ( ) ;
3902
+ expect ( count ) . toBe ( 4 ) ;
3903
+ expect ( values [ 3 ] ) . toEqual ( { 'undefined' : true } ) ;
3904
+ } ) ;
3905
+
3871
3906
} ) ;
3872
3907
3873
3908
describe ( 'locals' , function ( ) {
You can’t perform that action at this time.
0 commit comments