MCPcopy
hub / github.com/tdewolff/minify / minifyVarDecl

Method minifyVarDecl

js/js.go:529–556  ·  view source on GitHub ↗
(decl *js.VarDecl, onlyDefines bool)

Source from the content-addressed store, hash-verified

527}
528
529func (m *jsMinifier) minifyVarDecl(decl *js.VarDecl, onlyDefines bool) {
530 if len(decl.List) == 0 {
531 return
532 } else if decl.TokenType == js.ErrorToken {
533 // remove 'var' when hoisting variables
534 first := true
535 for _, item := range decl.List {
536 if item.Default != nil || !onlyDefines {
537 if !first {
538 m.write(commaBytes)
539 }
540 m.minifyBindingElement(item)
541 first = false
542 }
543 }
544 } else {
545 m.optimizeVarOrder(decl)
546
547 m.write(decl.TokenType.Bytes())
548 m.writeSpaceBeforeIdent()
549 for i, item := range decl.List {
550 if i != 0 {
551 m.write(commaBytes)
552 }
553 m.minifyBindingElement(item)
554 }
555 }
556}
557
558func (m *jsMinifier) minifyFuncDecl(decl *js.FuncDecl, inExpr bool) {
559 // TODO: rewrite to arrow function if doe snot refer to this?

Callers 2

minifyStmtMethod · 0.95
minifyExprMethod · 0.95

Calls 6

writeMethod · 0.95
minifyBindingElementMethod · 0.95
optimizeVarOrderMethod · 0.95
writeSpaceBeforeIdentMethod · 0.95
lenFunction · 0.85
BytesMethod · 0.45

Tested by

no test coverage detected