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 {
833833
834834 // A redeclaration of an existing variable is a modification
835835 if ( local ) {
836- this . registerConstantViolation ( bindingPath ) ;
836+ local . reassign ( bindingPath ) ;
837837 } else {
838838 this . bindings [ name ] = new Binding ( {
839839 identifier : id ,
Original file line number Diff line number Diff line change @@ -1138,4 +1138,25 @@ describe("scope", () => {
11381138 ` ) ;
11391139 } ) ;
11401140 } ) ;
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+ } ) ;
11411162} ) ;
You can’t perform that action at this time.
0 commit comments