Skip to content

Commit be67827

Browse files
committed
compiler: Replace old importer with x/tools/go/gcimporter15.
The copied importer is an old package from Go 1.5 times. It was a copy of x/tools/go/importer package. It does not support type aliases added in Go 1.9. Encountering a type alias declaration caused a panic. Use the gcimporter15 package instead. It supports a more modern binary export format and includes support for type aliases. The gcimporter15 package is marked as deprecated and said to be deleted in October 2017. However, the replacement package does not expose the functionality suitable for GopherJS current needs. That means we'll need to find a resolution by the time it's deleted. It will either be a feature request to add the needed functionality, a rewrite of GopherJS code to use available functionality, or vendoring/copying the code. Updates #278.
1 parent 62cb4ed commit be67827

File tree

5 files changed

+4
-1002
lines changed

5 files changed

+4
-1002
lines changed

compiler/compiler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"strings"
1313

1414
"github.com/gopherjs/gopherjs/compiler/prelude"
15-
"github.com/gopherjs/gopherjs/third_party/importer"
15+
"golang.org/x/tools/go/gcimporter15"
1616
)
1717

1818
var sizes32 = &types.StdSizes{WordSize: 4, MaxAlign: 8}
@@ -239,7 +239,7 @@ func ReadArchive(filename, path string, r io.Reader, packages map[string]*types.
239239
}
240240

241241
var err error
242-
_, packages[path], err = importer.ImportData(packages, a.ExportData)
242+
_, packages[path], err = gcimporter.BImportData(token.NewFileSet(), packages, a.ExportData, path)
243243
if err != nil {
244244
return nil, err
245245
}

compiler/package.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import (
1212
"strings"
1313

1414
"github.com/gopherjs/gopherjs/compiler/analysis"
15-
"github.com/gopherjs/gopherjs/third_party/importer"
1615
"github.com/neelance/astrewrite"
16+
"golang.org/x/tools/go/gcimporter15"
1717
"golang.org/x/tools/go/types/typeutil"
1818
)
1919

@@ -164,7 +164,7 @@ func Compile(importPath string, files []*ast.File, fileSet *token.FileSet, impor
164164
}
165165
importContext.Packages[importPath] = typesPkg
166166

167-
exportData := importer.ExportData(typesPkg)
167+
exportData := gcimporter.BExportData(nil, typesPkg)
168168
encodedFileSet := bytes.NewBuffer(nil)
169169
if err := fileSet.Write(json.NewEncoder(encodedFileSet).Encode); err != nil {
170170
return nil, err

0 commit comments

Comments
 (0)