@@ -25,7 +25,6 @@ import (
2525 "time"
2626
2727 "github.com/fsnotify/fsnotify"
28- "github.com/neelance/sourcemap"
2928 log "github.com/sirupsen/logrus"
3029 "golang.org/x/tools/go/buildutil"
3130
@@ -1175,12 +1174,6 @@ func (s *Session) compilePackage(srcs *sources.Sources, tContext *types.Context)
11751174 return nil , err
11761175 }
11771176
1178- for _ , jsFile := range srcs .JSFiles {
1179- archive .IncJSCode = append (archive .IncJSCode , []byte ("\t (function() {\n " )... )
1180- archive .IncJSCode = append (archive .IncJSCode , jsFile .Content ... )
1181- archive .IncJSCode = append (archive .IncJSCode , []byte ("\n \t }).call($global);\n " )... )
1182- }
1183-
11841177 if s .options .Verbose {
11851178 fmt .Println (srcs .ImportPath )
11861179 }
@@ -1243,8 +1236,8 @@ func (s *Session) ImportResolverFor(srcDir string) func(string) (*compiler.Archi
12431236
12441237// SourceMappingCallback returns a callback for [github.com/gopherjs/gopherjs/compiler.SourceMapFilter]
12451238// configured for the current build session.
1246- func (s * Session ) SourceMappingCallback ( m * sourcemap. Map ) func ( generatedLine , generatedColumn int , originalPos token. Position , originalName string ) {
1247- return NewMappingCallback ( m , s .xctx .Env ().GOROOT , s .xctx .Env ().GOPATH , s .options .MapToLocalDisk )
1239+ func (s * Session ) EnableMapping ( filter * sourcemapx. Filter , jsFileName string ) {
1240+ filter . EnableMapping ( jsFileName , s .xctx .Env ().GOROOT , s .xctx .Env ().GOPATH , s .options .MapToLocalDisk )
12481241}
12491242
12501243// WriteCommandPackage writes the final JavaScript output file at pkgObj path.
@@ -1260,19 +1253,18 @@ func (s *Session) WriteCommandPackage(archive *compiler.Archive, pkgObj string)
12601253
12611254 sourceMapFilter := & sourcemapx.Filter {Writer : codeFile }
12621255 if s .options .CreateMapFile {
1263- m := & sourcemap.Map {File : filepath .Base (pkgObj )}
1256+ s .EnableMapping (sourceMapFilter , filepath .Base (pkgObj ))
1257+
12641258 mapFile , err := os .Create (pkgObj + ".map" )
12651259 if err != nil {
12661260 return err
12671261 }
12681262
12691263 defer func () {
1270- m . WriteTo (mapFile )
1264+ sourceMapFilter . WriteMappingTo (mapFile )
12711265 mapFile .Close ()
12721266 fmt .Fprintf (codeFile , "//# sourceMappingURL=%s.map\n " , filepath .Base (pkgObj ))
12731267 }()
1274-
1275- sourceMapFilter .MappingCallback = s .SourceMappingCallback (m )
12761268 }
12771269
12781270 deps , err := compiler .ImportDependencies (archive , s .ImportResolverFor ("" ))
@@ -1282,50 +1274,6 @@ func (s *Session) WriteCommandPackage(archive *compiler.Archive, pkgObj string)
12821274 return compiler .WriteProgramCode (deps , sourceMapFilter , s .GoRelease ())
12831275}
12841276
1285- // NewMappingCallback creates a new callback for source map generation.
1286- func NewMappingCallback (m * sourcemap.Map , goroot , gopath string , localMap bool ) func (generatedLine , generatedColumn int , originalPos token.Position , originalName string ) {
1287- return func (generatedLine , generatedColumn int , originalPos token.Position , originalName string ) {
1288- mapping := & sourcemap.Mapping {GeneratedLine : generatedLine , GeneratedColumn : generatedColumn }
1289-
1290- if originalPos .IsValid () {
1291- file := originalPos .Filename
1292-
1293- switch hasGopathPrefix , prefixLen := hasGopathPrefix (file , gopath ); {
1294- case localMap :
1295- // no-op: keep file as-is
1296- case hasGopathPrefix :
1297- file = filepath .ToSlash (file [prefixLen + 4 :])
1298- case strings .HasPrefix (file , goroot ):
1299- file = filepath .ToSlash (file [len (goroot )+ 4 :])
1300- default :
1301- file = filepath .Base (file )
1302- }
1303- mapping .OriginalFile = file
1304- mapping .OriginalLine = originalPos .Line
1305- mapping .OriginalColumn = originalPos .Column
1306- }
1307-
1308- if originalName != "" {
1309- mapping .OriginalName = originalName
1310- }
1311-
1312- m .AddMapping (mapping )
1313- }
1314- }
1315-
1316- // hasGopathPrefix returns true and the length of the matched GOPATH workspace,
1317- // iff file has a prefix that matches one of the GOPATH workspaces.
1318- func hasGopathPrefix (file , gopath string ) (hasGopathPrefix bool , prefixLen int ) {
1319- gopathWorkspaces := filepath .SplitList (gopath )
1320- for _ , gopathWorkspace := range gopathWorkspaces {
1321- gopathWorkspace = filepath .Clean (gopathWorkspace )
1322- if strings .HasPrefix (file , gopathWorkspace ) {
1323- return true , len (gopathWorkspace )
1324- }
1325- }
1326- return false , 0
1327- }
1328-
13291277// WaitForChange watches file system events and returns if either when one of
13301278// the source files is modified.
13311279func (s * Session ) WaitForChange () {
0 commit comments