@@ -206,6 +206,7 @@ func (o *Options) PrintSuccess(format string, a ...interface{}) {
206
206
207
207
type PackageData struct {
208
208
* build.Package
209
+ JsFiles []string
209
210
SrcModTime time.Time
210
211
UpToDate bool
211
212
Archive * compiler.Archive
@@ -283,10 +284,17 @@ func (s *Session) BuildFiles(filenames []string, pkgObj string, packagePath stri
283
284
Name : "main" ,
284
285
ImportPath : "main" ,
285
286
Dir : packagePath ,
286
- GoFiles : filenames ,
287
287
},
288
288
}
289
289
290
+ for _ , file := range filenames {
291
+ if strings .HasSuffix (file , ".js" ) {
292
+ pkg .JsFiles = append (pkg .JsFiles , file )
293
+ continue
294
+ }
295
+ pkg .GoFiles = append (pkg .GoFiles , file )
296
+ }
297
+
290
298
if err := s .BuildPackage (pkg ); err != nil {
291
299
return err
292
300
}
@@ -309,6 +317,17 @@ func (s *Session) ImportPackage(path string) (*compiler.Archive, error) {
309
317
return nil , err
310
318
}
311
319
pkg := & PackageData {Package : buildPkg }
320
+
321
+ files , err := ioutil .ReadDir (pkg .Dir )
322
+ if err != nil {
323
+ return nil , err
324
+ }
325
+ for _ , file := range files {
326
+ if strings .HasSuffix (file .Name (), ".js" ) {
327
+ pkg .JsFiles = append (pkg .JsFiles , filepath .Join (pkg .Dir , file .Name ()))
328
+ }
329
+ }
330
+
312
331
if err := s .BuildPackage (pkg ); err != nil {
313
332
return nil , err
314
333
}
@@ -417,6 +436,18 @@ func (s *Session) BuildPackage(pkg *PackageData) error {
417
436
return err
418
437
}
419
438
439
+ var jsDecls []compiler.Decl
440
+ for _ , jsFile := range pkg .JsFiles {
441
+ code , err := ioutil .ReadFile (jsFile )
442
+ if err != nil {
443
+ return err
444
+ }
445
+ jsDecls = append (jsDecls , compiler.Decl {
446
+ BodyCode : append (code , '\n' ),
447
+ })
448
+ }
449
+ pkg .Archive .Declarations = append (jsDecls , pkg .Archive .Declarations ... )
450
+
420
451
if s .options .Verbose {
421
452
fmt .Println (pkg .ImportPath )
422
453
}
0 commit comments