diff --git a/js/js.go b/js/js.go index 40fad480a..05681041d 100644 --- a/js/js.go +++ b/js/js.go @@ -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 { diff --git a/js/js_test.go b/js/js_test.go index 4106f3497..d3bc051b3 100644 --- a/js/js_test.go +++ b/js/js_test.go @@ -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]{}`},