@@ -21,12 +21,14 @@ import (
2121const pseudoFileName = `prog.go`
2222
2323type runner struct {
24- cache * packageCache
24+ verbose bool
25+ cache * packageCache
2526}
2627
27- func New (fetcher common.Fetcher ) common.Runner {
28+ func New (verbose bool , fetcher common.Fetcher ) common.Runner {
2829 return & runner {
29- cache : newPackageCache (fetcher ),
30+ verbose : verbose ,
31+ cache : newPackageCache (fetcher ),
3032 }
3133}
3234
@@ -67,13 +69,18 @@ func (r *runner) Compile(goCode string, then func(string, error)) {
6769}
6870
6971func (r * runner ) syncCompile (goCode string ) (string , error ) {
72+ if r .verbose {
73+ println (`starting compile` )
74+ }
75+
7076 fileSet := token .NewFileSet ()
7177 file , err := parser .ParseFile (fileSet , pseudoFileName , goCode , parser .ParseComments )
7278 if err != nil {
7379 return `` , err
7480 }
7581
76- // TODO: Need to detect if [goCode] has no main method but instead has Test, Bench, or Example, methods.
82+ // TODO(grantnelson-wf): Idea: We could detect if [goCode] has no main method and
83+ // instead has Test, Bench, or Example, methods, then run the code as a test.
7784
7885 root := & sources.Sources {
7986 ImportPath : `main` ,
@@ -88,15 +95,24 @@ func (r *runner) syncCompile(goCode string) (string, error) {
8895
8996 allSources , err := r .collectAllSources (root )
9097 if err != nil {
98+ if r .verbose {
99+ println (`compile failed` )
100+ }
91101 return `` , err
92102 }
93103
94104 archives , err := r .prepareAndCompilePackages (root .ImportPath , allSources )
95105 if err != nil {
106+ if r .verbose {
107+ println (`compile failed` )
108+ }
96109 return `` , err
97110 }
98111
99112 jsCode := r .write (archives )
113+ if r .verbose {
114+ println (`done compiling` )
115+ }
100116 return jsCode , nil
101117}
102118
@@ -187,6 +203,9 @@ func (r *runner) write(allPkgs []*compiler.Archive) string {
187203}
188204
189205func (r * runner ) Run (jsCode string ) {
206+ if r .verbose {
207+ println (`running compiled code` )
208+ }
190209 js .Global .Set ("$checkForDeadlock" , true )
191210 js .Global .Call ("eval" , js .InternalObject (jsCode ))
192211}
0 commit comments