@@ -10,6 +10,7 @@ import (
10
10
"strings"
11
11
"time"
12
12
13
+ "github.com/gopherjs/gopherjs.github.io/playground/internal/imports"
13
14
"github.com/gopherjs/gopherjs/compiler"
14
15
"github.com/gopherjs/gopherjs/js"
15
16
"github.com/neelance/go-angularjs"
@@ -52,7 +53,7 @@ func main() {
52
53
})
53
54
}()
54
55
} else {
55
- scope .Set ("code" , "package main\n \n import (\n \t \" fmt\" \n \t \" github.com/gopherjs/gopherjs/js\" \n )\n \n func main() {\n \t fmt.Println(\" Hello, playground\" )\n \t js.Global.Call(\" alert\" , \" Hello, JavaScript\" )\n \t println(\" Hello, JS console\" )\n }\n " )
56
+ scope .Set ("code" , "package main\n \n import (\n \t \" fmt\" \n \n \ t\" github.com/gopherjs/gopherjs/js\" \n )\n \n func main() {\n \t fmt.Println(\" Hello, playground\" )\n \t js.Global.Call(\" alert\" , \" Hello, JavaScript\" )\n \t println(\" Hello, JS console\" )\n }\n " )
56
57
close (codeReady )
57
58
}
58
59
scope .Set ("shareUrl" , "" )
@@ -200,13 +201,26 @@ func main() {
200
201
}()
201
202
202
203
scope .Set ("format" , func () {
203
- out , err := format .Source ([]byte (scope .Get ("code" ).String ()))
204
- if err != nil {
205
- scope .Set ("output" , []Line {Line {"type" : "err" , "content" : err .Error ()}})
206
- return
207
- }
208
- scope .Set ("code" , string (out ))
209
- scope .Set ("output" , []Line {})
204
+ go func () {
205
+ var out []byte
206
+ var err error
207
+ switch dom .GetWindow ().Document ().GetElementByID ("imports" ).(* dom.HTMLInputElement ).Checked {
208
+ case true :
209
+ out , err = imports .Process ("prog.go" , []byte (scope .Get ("code" ).String ()), nil )
210
+ case false :
211
+ out , err = format .Source ([]byte (scope .Get ("code" ).String ()))
212
+ }
213
+ if err != nil {
214
+ scope .Apply (func () {
215
+ scope .Set ("output" , []Line {Line {"type" : "err" , "content" : err .Error ()}})
216
+ })
217
+ return
218
+ }
219
+ scope .Apply (func () {
220
+ scope .Set ("code" , string (out ))
221
+ scope .Set ("output" , []Line {})
222
+ })
223
+ }()
210
224
})
211
225
212
226
scope .Set ("share" , func () {
0 commit comments