Skip to content

Commit 8d83d5e

Browse files
reduce passing PackageData
1 parent 289ebba commit 8d83d5e

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

build/build.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,7 @@ func (s *Session) BuildPackage(pkg *PackageData) (*compiler.Archive, error) {
10181018

10191019
importContext := &compiler.ImportContext{
10201020
Packages: s.Types,
1021-
Import: s.ImportResolverFor(pkg),
1021+
Import: s.ImportResolverFor(pkg.Dir),
10221022
}
10231023
archive, err := compiler.Compile(pkg.ImportPath, files, fileSet, importContext, s.options.Minify)
10241024
if err != nil {
@@ -1043,12 +1043,12 @@ func (s *Session) BuildPackage(pkg *PackageData) (*compiler.Archive, error) {
10431043

10441044
// ImportResolverFor returns a function which returns a compiled package archive
10451045
// given an import path.
1046-
func (s *Session) ImportResolverFor(pkg *PackageData) func(string) (*compiler.Archive, error) {
1046+
func (s *Session) ImportResolverFor(srcDir string) func(string) (*compiler.Archive, error) {
10471047
return func(path string) (*compiler.Archive, error) {
10481048
if archive, ok := s.UpToDateArchives[path]; ok {
10491049
return archive, nil
10501050
}
1051-
_, archive, err := s.buildImportPathWithSrcDir(path, pkg.Dir)
1051+
_, archive, err := s.buildImportPathWithSrcDir(path, srcDir)
10521052
return archive, err
10531053
}
10541054
}
@@ -1087,13 +1087,7 @@ func (s *Session) WriteCommandPackage(archive *compiler.Archive, pkgObj string)
10871087
sourceMapFilter.MappingCallback = s.SourceMappingCallback(m)
10881088
}
10891089

1090-
deps, err := compiler.ImportDependencies(archive, func(path string) (*compiler.Archive, error) {
1091-
if archive, ok := s.UpToDateArchives[path]; ok {
1092-
return archive, nil
1093-
}
1094-
_, archive, err := s.buildImportPathWithSrcDir(path, "")
1095-
return archive, err
1096-
})
1090+
deps, err := compiler.ImportDependencies(archive, s.ImportResolverFor(""))
10971091
if err != nil {
10981092
return err
10991093
}

tool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ func main() {
389389
}
390390
importContext := &compiler.ImportContext{
391391
Packages: s.Types,
392-
Import: s.ImportResolverFor(mainPkg),
392+
Import: s.ImportResolverFor(mainPkg.Dir),
393393
}
394394
mainPkgArchive, err := compiler.Compile(mainPkg.ImportPath, []*ast.File{mainFile}, fset, importContext, options.Minify)
395395
if err != nil {

0 commit comments

Comments
 (0)