File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -833,7 +833,7 @@ class Scope {
833
833
834
834
// A redeclaration of an existing variable is a modification
835
835
if ( local ) {
836
- this . registerConstantViolation ( bindingPath ) ;
836
+ local . reassign ( bindingPath ) ;
837
837
} else {
838
838
this . bindings [ name ] = new Binding ( {
839
839
identifier : id ,
Original file line number Diff line number Diff line change @@ -1138,4 +1138,25 @@ describe("scope", () => {
1138
1138
` ) ;
1139
1139
} ) ;
1140
1140
} ) ;
1141
+
1142
+ describe ( "constantViolations" , ( ) => {
1143
+ it ( "var redeclarations should not be treated as constantViolations" , ( ) => {
1144
+ const program = getPath ( `
1145
+ function v() { }
1146
+ function f() {
1147
+ var a = 1;
1148
+ var {
1149
+ currentPoint: a,
1150
+ centp: v,
1151
+ } = {};
1152
+ }
1153
+ ` ) ;
1154
+
1155
+ const bindingV = program . scope . getBinding ( "v" ) ;
1156
+ expect ( bindingV . constantViolations ) . toHaveLength ( 0 ) ;
1157
+
1158
+ const bindingA = program . get ( "body.1.body" ) . scope . getBinding ( "a" ) ;
1159
+ expect ( bindingA . constantViolations ) . toHaveLength ( 1 ) ;
1160
+ } ) ;
1161
+ } ) ;
1141
1162
} ) ;
You can’t perform that action at this time.
0 commit comments