@@ -30,6 +30,7 @@ import (
3030 "github.com/gopherjs/gopherjs/compiler/jsFile"
3131 "github.com/gopherjs/gopherjs/compiler/sources"
3232 "github.com/gopherjs/gopherjs/internal/errorList"
33+ "github.com/gopherjs/gopherjs/internal/sourcemapx"
3334 "github.com/gopherjs/gopherjs/internal/testmain"
3435 log "github.com/sirupsen/logrus"
3536
@@ -1216,9 +1217,9 @@ func (s *Session) ImportResolverFor(srcDir string) func(string) (*compiler.Archi
12161217 }
12171218}
12181219
1219- // SourceMappingCallback returns a call back for compiler.SourceMapFilter
1220+ // SourceMappingCallback returns a callback for [github.com/gopherjs/gopherjs/ compiler.SourceMapFilter]
12201221// configured for the current build session.
1221- func (s * Session ) SourceMappingCallback (m * sourcemap.Map ) func (generatedLine , generatedColumn int , originalPos token.Position ) {
1222+ func (s * Session ) SourceMappingCallback (m * sourcemap.Map ) func (generatedLine , generatedColumn int , originalPos token.Position , originalName string ) {
12221223 return NewMappingCallback (m , s .xctx .Env ().GOROOT , s .xctx .Env ().GOPATH , s .options .MapToLocalDisk )
12231224}
12241225
@@ -1233,7 +1234,7 @@ func (s *Session) WriteCommandPackage(archive *compiler.Archive, pkgObj string)
12331234 }
12341235 defer codeFile .Close ()
12351236
1236- sourceMapFilter := & compiler. SourceMapFilter {Writer : codeFile }
1237+ sourceMapFilter := & sourcemapx. Filter {Writer : codeFile }
12371238 if s .options .CreateMapFile {
12381239 m := & sourcemap.Map {File : filepath .Base (pkgObj )}
12391240 mapFile , err := os .Create (pkgObj + ".map" )
@@ -1258,27 +1259,33 @@ func (s *Session) WriteCommandPackage(archive *compiler.Archive, pkgObj string)
12581259}
12591260
12601261// NewMappingCallback creates a new callback for source map generation.
1261- func NewMappingCallback (m * sourcemap.Map , goroot , gopath string , localMap bool ) func (generatedLine , generatedColumn int , originalPos token.Position ) {
1262- return func (generatedLine , generatedColumn int , originalPos token.Position ) {
1263- if ! originalPos .IsValid () {
1264- m .AddMapping (& sourcemap.Mapping {GeneratedLine : generatedLine , GeneratedColumn : generatedColumn })
1265- return
1262+ func NewMappingCallback (m * sourcemap.Map , goroot , gopath string , localMap bool ) func (generatedLine , generatedColumn int , originalPos token.Position , originalName string ) {
1263+ return func (generatedLine , generatedColumn int , originalPos token.Position , originalName string ) {
1264+ mapping := & sourcemap.Mapping {GeneratedLine : generatedLine , GeneratedColumn : generatedColumn }
1265+
1266+ if originalPos .IsValid () {
1267+ file := originalPos .Filename
1268+
1269+ switch hasGopathPrefix , prefixLen := hasGopathPrefix (file , gopath ); {
1270+ case localMap :
1271+ // no-op: keep file as-is
1272+ case hasGopathPrefix :
1273+ file = filepath .ToSlash (file [prefixLen + 4 :])
1274+ case strings .HasPrefix (file , goroot ):
1275+ file = filepath .ToSlash (file [len (goroot )+ 4 :])
1276+ default :
1277+ file = filepath .Base (file )
1278+ }
1279+ mapping .OriginalFile = file
1280+ mapping .OriginalLine = originalPos .Line
1281+ mapping .OriginalColumn = originalPos .Column
12661282 }
12671283
1268- file := originalPos .Filename
1269-
1270- switch hasGopathPrefix , prefixLen := hasGopathPrefix (file , gopath ); {
1271- case localMap :
1272- // no-op: keep file as-is
1273- case hasGopathPrefix :
1274- file = filepath .ToSlash (file [prefixLen + 4 :])
1275- case strings .HasPrefix (file , goroot ):
1276- file = filepath .ToSlash (file [len (goroot )+ 4 :])
1277- default :
1278- file = filepath .Base (file )
1284+ if originalName != "" {
1285+ mapping .OriginalName = originalName
12791286 }
12801287
1281- m .AddMapping (& sourcemap. Mapping { GeneratedLine : generatedLine , GeneratedColumn : generatedColumn , OriginalFile : file , OriginalLine : originalPos . Line , OriginalColumn : originalPos . Column } )
1288+ m .AddMapping (mapping )
12821289 }
12831290}
12841291
0 commit comments