@@ -59,12 +59,12 @@ func main() {
59
59
scope .Set ("showShareUrl" , false )
60
60
61
61
packages := make (map [string ]* compiler.Archive )
62
- var pkgsToLoad [] string
62
+ var pkgsToLoad map [ string ] bool
63
63
importContext := compiler .NewImportContext (func (path string ) (* compiler.Archive , error ) {
64
64
if pkg , found := packages [path ]; found {
65
65
return pkg , nil
66
66
}
67
- pkgsToLoad = append ( pkgsToLoad , path )
67
+ pkgsToLoad [ path ] = true
68
68
return & compiler.Archive {}, nil
69
69
})
70
70
fileSet := token .NewFileSet ()
@@ -116,7 +116,7 @@ func main() {
116
116
run = func (loadOnly bool ) {
117
117
output = nil
118
118
scope .Set ("output" , output )
119
- pkgsToLoad = nil
119
+ pkgsToLoad = make ( map [ string ] bool )
120
120
121
121
file , err := parser .ParseFile (fileSet , "prog.go" , []byte (scope .Get ("code" ).String ()), parser .ParseComments )
122
122
if err != nil {
@@ -135,7 +135,7 @@ func main() {
135
135
packages ["main" ] = mainPkg
136
136
if err != nil && len (pkgsToLoad ) == 0 {
137
137
if list , ok := err .(compiler.ErrorList ); ok {
138
- output := make ( []Line , 0 )
138
+ var output []Line
139
139
for _ , entry := range list {
140
140
output = append (output , Line {"type" : "err" , "content" : entry .Error ()})
141
141
}
@@ -153,12 +153,10 @@ func main() {
153
153
154
154
if len (pkgsToLoad ) != 0 {
155
155
pkgsReceived = 0
156
- for _ , p := range pkgsToLoad {
157
- path := p
158
-
156
+ for path := range pkgsToLoad {
159
157
req := xhr .NewRequest ("GET" , "pkg/" + path + ".a.js" )
160
158
req .ResponseType = xhr .ArrayBuffer
161
- go func () {
159
+ go func (path string ) {
162
160
err := req .Send (nil )
163
161
if err != nil || req .Status != 200 {
164
162
scope .Apply (func () {
@@ -179,7 +177,7 @@ func main() {
179
177
if pkgsReceived == len (pkgsToLoad ) {
180
178
run (loadOnly )
181
179
}
182
- }()
180
+ }(path )
183
181
}
184
182
return
185
183
}
0 commit comments