github.com/gopherjs/gopherjs@v1.19.0-beta1.0.20240506212314-27071a8796e4/compiler/prelude/prelude.go (about) 1 package prelude 2 3 import ( 4 _ "embed" 5 6 "github.com/evanw/esbuild/pkg/api" 7 log "github.com/sirupsen/logrus" 8 ) 9 10 // Prelude is the GopherJS JavaScript interop layer. 11 var Prelude = prelude + numeric + types + goroutines + jsmapping 12 13 //go:embed prelude.js 14 var prelude string 15 16 //go:embed types.js 17 var types string 18 19 //go:embed numeric.js 20 var numeric string 21 22 //go:embed jsmapping.js 23 var jsmapping string 24 25 //go:embed goroutines.js 26 var goroutines string 27 28 func Minified() string { 29 result := api.Transform(Prelude, api.TransformOptions{ 30 Target: api.ES2015, 31 MinifyWhitespace: true, 32 MinifyIdentifiers: true, 33 MinifySyntax: true, 34 KeepNames: true, 35 Charset: api.CharsetUTF8, 36 LegalComments: api.LegalCommentsEndOfFile, 37 }) 38 for _, w := range result.Warnings { 39 log.Warnf("%d:%d: %s\n%s\n", w.Location.Line, w.Location.Column, w.Text, w.Location.LineText) 40 } 41 if errCount := len(result.Errors); errCount > 0 { 42 for _, e := range result.Errors { 43 log.Errorf("%d:%d: %s\n%s\n", e.Location.Line, e.Location.Column, e.Text, e.Location.LineText) 44 } 45 log.Fatalf("Prelude minification failed with %d errors", errCount) 46 } 47 return string(result.Code) 48 }