Skip to content

Commit

Permalink
fix bug with no-identifier var in dead branches
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Feb 23, 2024
1 parent 40711af commit a064abc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/js_parser/js_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -8355,6 +8355,9 @@ func shouldKeepStmtInDeadControlFlow(stmt js_ast.Stmt) bool {
for _, decl := range s.Decls {
identifiers = findIdentifiers(decl.Binding, identifiers)
}
if len(identifiers) == 0 {
return false
}
s.Decls = identifiers
return true

Expand Down
2 changes: 2 additions & 0 deletions internal/js_parser/js_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5241,6 +5241,8 @@ func TestTrimCodeInDeadControlFlow(t *testing.T) {
expectPrintedMangle(t, "if (1) a(); else { var a = b }", "if (1)\n a();\nelse\n var a;\n")
expectPrintedMangle(t, "if (1) a(); else { var [a] = b }", "if (1)\n a();\nelse\n var a;\n")
expectPrintedMangle(t, "if (1) a(); else { var {x: a} = b }", "if (1)\n a();\nelse\n var a;\n")
expectPrintedMangle(t, "if (1) a(); else { var [] = b }", "a();\n")
expectPrintedMangle(t, "if (1) a(); else { var {} = b }", "a();\n")
expectPrintedMangle(t, "if (1) a(); else { function a() {} }", "if (1)\n a();\nelse\n var a;\n")
expectPrintedMangle(t, "if (1) a(); else { for(;;){var a} }", "if (1)\n a();\nelse\n for (; ; )\n var a;\n")
expectPrintedMangle(t, "if (1) { a(); b() } else { var a; var b; }", "if (1)\n a(), b();\nelse\n var a, b;\n")
Expand Down

0 comments on commit a064abc

Please sign in to comment.