Skip to content

Commit

Permalink
JS: fix bug in var decl merging with for-in statements, fixes #619
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Oct 26, 2023
1 parent 2e816a4 commit 8e38b17
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions js/js_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,7 @@ func TestJS(t *testing.T) {
{`export default function Foo(){a}Foo.prototype.bar=b`, `export default function Foo(){a}Foo.prototype.bar=b`}, // #525
{`(e=1,e=2)`, `e=1,e=2`}, // #528
{`"\x00\x31 \0\u0000"`, `"\x001 \0\x00"`}, // #577
{`function transform(){{var aaaa=[];for(var b=0;;){}for(var b in aaaa){}var aaaa=[];for(var b=0;;){}}}`, `function transform(){{for(var aaaa=[],b=0;;);for(b in aaaa);for(aaaa=[],b=0;;)}}`}, // #619
}

m := minify.New()
Expand Down
12 changes: 7 additions & 5 deletions js/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,13 @@ RemoveVarsLoop:
if value != nil {
// variable declaration must be somewhere else, find and remove it
for _, decl2 := range decl.Scope.Func.VarDecls {
for i, item := range decl2.List {
if v, ok := item.Binding.(*js.Var); ok && item.Default == nil && v == vbind {
v.Uses--
decl2.List = append(decl2.List[:i], decl2.List[i+1:]...)
continue RemoveVarsLoop
if !decl2.InForInOf {
for i, item := range decl2.List {
if v, ok := item.Binding.(*js.Var); ok && item.Default == nil && v == vbind {
v.Uses--
decl2.List = append(decl2.List[:i], decl2.List[i+1:]...)
continue RemoveVarsLoop
}
}
}
}
Expand Down

0 comments on commit 8e38b17

Please sign in to comment.