@@ -206,6 +206,7 @@ func (o *Options) PrintSuccess(format string, a ...interface{}) {
206206
207207type PackageData struct {
208208 * build.Package
209+ JsFiles []string
209210 SrcModTime time.Time
210211 UpToDate bool
211212 Archive * compiler.Archive
@@ -283,10 +284,17 @@ func (s *Session) BuildFiles(filenames []string, pkgObj string, packagePath stri
283284 Name : "main" ,
284285 ImportPath : "main" ,
285286 Dir : packagePath ,
286- GoFiles : filenames ,
287287 },
288288 }
289289
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+
290298 if err := s .BuildPackage (pkg ); err != nil {
291299 return err
292300 }
@@ -309,6 +317,17 @@ func (s *Session) ImportPackage(path string) (*compiler.Archive, error) {
309317 return nil , err
310318 }
311319 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+
312331 if err := s .BuildPackage (pkg ); err != nil {
313332 return nil , err
314333 }
@@ -417,6 +436,18 @@ func (s *Session) BuildPackage(pkg *PackageData) error {
417436 return err
418437 }
419438
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+
420451 if s .options .Verbose {
421452 fmt .Println (pkg .ImportPath )
422453 }
0 commit comments