Skip to content

Commit

Permalink
JS: don't minify undefined/Infinity if that variable was declared, fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Jan 20, 2025
1 parent ee34e32 commit b60a115
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions js/js.go
Original file line number Diff line number Diff line change
Expand Up @@ -863,13 +863,13 @@ func (m *jsMinifier) minifyExpr(i js.IExpr, prec js.OpPrec) {
expr = expr.Link
}
data := expr.Data
if bytes.Equal(data, undefinedBytes) { // TODO: only if not defined
if expr.Decl == js.NoDecl && bytes.Equal(data, undefinedBytes) {
if js.OpMember < prec {
m.write(groupedZeroIndexBytes)
} else {
m.write(zeroIndexBytes)
}
} else if bytes.Equal(data, infinityBytes) { // TODO: only if not defined
} else if expr.Decl == js.NoDecl && bytes.Equal(data, infinityBytes) {
if js.OpMul < prec {
m.write(groupedOneDivZeroBytes)
} else {
Expand Down
4 changes: 2 additions & 2 deletions js/js_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,11 @@ func TestJS(t *testing.T) {
{`x=undefined`, `x=0[0]`},
{`x=undefined()`, `x=0[0]()`},
{`x=undefined.a`, `x=0[0].a`},
//{`{const undefined=5;x=undefined}`, `{const undefined=5;x=undefined}`},
{`{const undefined=5;x=undefined}`, `{const undefined=5;x=undefined}`},
{`x=Infinity`, `x=1/0`},
{`x=Infinity()`, `x=(1/0)()`},
{`x=2**Infinity`, `x=2**(1/0)`},
//{`{const Infinity=5;x=Infinity}`, `{const Infinity=5;x=Infinity}`},
{`{const Infinity=5;x=Infinity}`, `{const Infinity=5;x=Infinity}`},
{`!""`, `!0`},
{`!"foobar"`, `!1`},
{`class a extends undefined {}`, `class a extends 0[0]{}`},
Expand Down

0 comments on commit b60a115

Please sign in to comment.