Skip to content

Commit 398e7dc

Browse files
committed
WIP: Updates for minor changes to the go/types API.
The type of go/types.Importer has changed from a func to an interface. Make appropriate changes. TODO: Re-organize code so that if importError == nil { importError = err } still takes place. It's needed to resolve #119.
1 parent f0eff95 commit 398e7dc

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

compiler/package.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,23 @@ func NewImportContext(importFunc func(string) (*Archive, error)) *ImportContext
6666
}
6767
}
6868

69+
// packageImporter implements go/types.Importer interface.
70+
type packageImporter struct {
71+
importContext *ImportContext
72+
}
73+
74+
func (pi packageImporter) Import(path string) (*types.Package, error) {
75+
if _, err := pi.importContext.Import(path); err != nil {
76+
// TODO: Figure out if setting importError here is still needed; if so, preserve this behavior.
77+
// It's needed to resolve https://github.com/gopherjs/gopherjs/issues/119.
78+
/*if importError == nil {
79+
importError = err
80+
}*/
81+
return nil, err
82+
}
83+
return pi.importContext.Packages[path], nil
84+
}
85+
6986
func Compile(importPath string, files []*ast.File, fileSet *token.FileSet, importContext *ImportContext, minify bool) (*Archive, error) {
7087
typesInfo := &types.Info{
7188
Types: make(map[ast.Expr]types.TypeAndValue),
@@ -80,17 +97,8 @@ func Compile(importPath string, files []*ast.File, fileSet *token.FileSet, impor
8097
var errList ErrorList
8198
var previousErr error
8299
config := &types.Config{
83-
Packages: importContext.Packages,
84-
Import: func(_ map[string]*types.Package, path string) (*types.Package, error) {
85-
if _, err := importContext.Import(path); err != nil {
86-
if importError == nil {
87-
importError = err
88-
}
89-
return nil, err
90-
}
91-
return importContext.Packages[path], nil
92-
},
93-
Sizes: sizes32,
100+
Importer: packageImporter{importContext: importContext},
101+
Sizes: sizes32,
94102
Error: func(err error) {
95103
if previousErr != nil && previousErr.Error() == err.Error() {
96104
return

0 commit comments

Comments
 (0)