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

Method Minify

js/js.go:40–66  ·  view source on GitHub ↗

Minify minifies JS data, it reads from r and writes to w.

(_ *minify.M, w io.Writer, r io.Reader, params map[string]string)

Source from the content-addressed store, hash-verified

38
39// Minify minifies JS data, it reads from r and writes to w.
40func (o *Minifier) Minify(_ *minify.M, w io.Writer, r io.Reader, params map[string]string) error {
41 z := parse.NewInput(r)
42 ast, err := js.Parse(z, js.Options{
43 WhileToFor: true,
44 Inline: params != nil && params["inline"] == "1",
45 })
46 if err != nil {
47 return err
48 }
49
50 m := &jsMinifier{
51 o: o,
52 w: w,
53 renamer: newRenamer(!o.KeepVarNames, !o.useAlphabetVarNames),
54 }
55 m.hoistVars(&ast.BlockStmt)
56 ast.List = optimizeStmtList(ast.List, functionBlock)
57 for _, item := range ast.List {
58 m.writeSemicolon()
59 m.minifyStmt(item)
60 }
61
62 if _, err := w.Write(nil); err != nil {
63 return err
64 }
65 return nil
66}
67
68type expectExpr int
69

Callers 3

TestJSFunction · 0.95
TestJSVarRenamingFunction · 0.95
TestJSVersionFunction · 0.95

Implementers 9

cmdMinifierminify.go
Mminify.go
DummyMinifierminify_test.go
Minifierjs/js.go
Minifierhtml/html.go
Minifiercss/css.go
Minifierxml/xml.go
Minifierjson/json.go
Minifiersvg/svg.go

Calls 6

hoistVarsMethod · 0.95
writeSemicolonMethod · 0.95
minifyStmtMethod · 0.95
newRenamerFunction · 0.85
optimizeStmtListFunction · 0.85
WriteMethod · 0.45

Tested by 3

TestJSFunction · 0.76
TestJSVarRenamingFunction · 0.76
TestJSVersionFunction · 0.76