Skip to content

Commit

Permalink
JS: export statement's function name must remain for non-default decl…
Browse files Browse the repository at this point in the history
…arations, fixes #375
  • Loading branch information
tdewolff committed Feb 8, 2021
1 parent 2873b21 commit b5f25ca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 10 additions & 7 deletions js/js.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,13 +354,16 @@ func (m *jsMinifier) minifyStmt(i js.IStmt) {
if stmt.Decl != nil {
if stmt.Default {
m.write(spaceDefaultBytes)
}
m.writeSpaceBeforeIdent()
m.minifyExpr(stmt.Decl, js.OpAssign)
_, isHoistable := stmt.Decl.(*js.FuncDecl)
_, isClass := stmt.Decl.(*js.ClassDecl)
if !isHoistable && !isClass {
m.requireSemicolon()
m.writeSpaceBeforeIdent()
m.minifyExpr(stmt.Decl, js.OpAssign)
_, isHoistable := stmt.Decl.(*js.FuncDecl)
_, isClass := stmt.Decl.(*js.ClassDecl)
if !isHoistable && !isClass {
m.requireSemicolon()
}
} else {
m.writeSpaceBeforeIdent()
m.minifyStmt(stmt.Decl.(js.IStmt)) // can only be variable, function, or class decl
}
} else {
if len(stmt.List) == 1 && (len(stmt.List[0].Name) == 1 && stmt.List[0].Name[0] == '*' || stmt.List[0].Name == nil && len(stmt.List[0].Binding) == 1 && stmt.List[0].Binding[0] == '*') {
Expand Down
2 changes: 2 additions & 0 deletions js/js_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func TestJS(t *testing.T) {
{`export {a as b, c} from 'path'`, `export{a as b,c}from'path'`},
{`export {a as b, c}`, `export{a as b,c}`},
{`export var a = b`, `export var a=b`},
{`export function a(){}`, `export function a(){}`},
{`export default a = b`, `export default a=b`},
{`export default a = b;c=d`, `export default a=b;c=d`},
{`export default function a(){};c=d`, `export default function(){}c=d`},
Expand Down Expand Up @@ -642,6 +643,7 @@ func TestJS(t *testing.T) {
{`if(e?0:n=1,o=2){o.a}`, `(e?0:n=1,o=2)&&o.a`}, // #347
{`const a=(a,b)=>({...a,b})`, `const a=(a,b)=>({...a,b})`}, // #369
{`if(!a)debugger;`, `if(!a)debugger`}, // #370
{`export function a(b){}`, `export function a(b){}`}, // #375
}

m := minify.New()
Expand Down

0 comments on commit b5f25ca

Please sign in to comment.