Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ package main
import "github.com/gopherjs/gopherjs/js"

func main() {
js.Global.Set("pet", map[string]interface{}{
js.Global.Set("pet", map[string]any{
"New": New,
})
}
Expand Down
47 changes: 19 additions & 28 deletions build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ import (
"time"

"github.com/fsnotify/fsnotify"
"github.com/neelance/sourcemap"
log "github.com/sirupsen/logrus"
"golang.org/x/tools/go/buildutil"

"github.com/gopherjs/gopherjs/compiler"
"github.com/gopherjs/gopherjs/compiler/astutil"
"github.com/gopherjs/gopherjs/compiler/jsFile"
"github.com/gopherjs/gopherjs/compiler/incjs"
"github.com/gopherjs/gopherjs/compiler/sources"
"github.com/gopherjs/gopherjs/internal/errorList"
"github.com/gopherjs/gopherjs/internal/errlist"
"github.com/gopherjs/gopherjs/internal/testmain"
log "github.com/sirupsen/logrus"

"github.com/neelance/sourcemap"
"golang.org/x/tools/go/buildutil"
)

// DefaultGOROOT is the default GOROOT value for builds.
Expand Down Expand Up @@ -123,7 +123,7 @@ func ImportDir(dir string, mode build.ImportMode, installSuffix string, buildTag
// overrideInfo is used by parseAndAugment methods to manage
// directives and how the overlay and original are merged.
type overrideInfo struct {
// KeepOriginal indicates that the original code should be kept
// keepOriginal indicates that the original code should be kept
// but the identifier will be prefixed by `_gopherjs_original_foo`.
// If false the original code is removed.
keepOriginal bool
Expand Down Expand Up @@ -166,7 +166,7 @@ type overrideInfo struct {
// - Otherwise for identifiers that exist in the original and the overrides,
// the original is removed.
// - New identifiers that don't exist in original package get added.
func parseAndAugment(xctx XContext, pkg *PackageData, isTest bool, fileSet *token.FileSet) ([]*ast.File, []jsFile.JSFile, error) {
func parseAndAugment(xctx XContext, pkg *PackageData, isTest bool, fileSet *token.FileSet) ([]*ast.File, []incjs.File, error) {
jsFiles, overlayFiles := parseOverlayFiles(xctx, pkg, isTest, fileSet)

originalFiles, err := parserOriginalFiles(pkg, fileSet)
Expand Down Expand Up @@ -195,7 +195,7 @@ func parseAndAugment(xctx XContext, pkg *PackageData, isTest bool, fileSet *toke

// parseOverlayFiles loads and parses overlay files
// to augment the original files with.
func parseOverlayFiles(xctx XContext, pkg *PackageData, isTest bool, fileSet *token.FileSet) ([]jsFile.JSFile, []*ast.File) {
func parseOverlayFiles(xctx XContext, pkg *PackageData, isTest bool, fileSet *token.FileSet) ([]incjs.File, []*ast.File) {
isXTest := strings.HasSuffix(pkg.ImportPath, "_test")
importPath := pkg.ImportPath
if isXTest {
Expand Down Expand Up @@ -241,7 +241,7 @@ func parseOverlayFiles(xctx XContext, pkg *PackageData, isTest bool, fileSet *to
// parserOriginalFiles loads and parses the original files to augment.
func parserOriginalFiles(pkg *PackageData, fileSet *token.FileSet) ([]*ast.File, error) {
var files []*ast.File
var errList errorList.ErrorList
var errList errlist.ErrorList
for _, name := range pkg.GoFiles {
if !filepath.IsAbs(name) { // name might be absolute if specified directly. E.g., `gopherjs build /abs/file.go`.
name = filepath.Join(pkg.Dir, name)
Expand Down Expand Up @@ -610,15 +610,15 @@ type Options struct {
}

// PrintError message to the terminal.
func (o *Options) PrintError(format string, a ...interface{}) {
func (o *Options) PrintError(format string, a ...any) {
if o.Color {
format = "\x1B[31m" + format + "\x1B[39m"
}
fmt.Fprintf(os.Stderr, format, a...)
}

// PrintSuccess message to the terminal.
func (o *Options) PrintSuccess(format string, a ...interface{}) {
func (o *Options) PrintSuccess(format string, a ...any) {
if o.Color {
format = "\x1B[32m" + format + "\x1B[39m"
}
Expand All @@ -629,7 +629,7 @@ func (o *Options) PrintSuccess(format string, a ...interface{}) {
// GopherJS requires.
type PackageData struct {
*build.Package
JSFiles []jsFile.JSFile
JSFiles []incjs.File
// IsTest is true if the package is being built for running tests.
IsTest bool
SrcModTime time.Time
Expand Down Expand Up @@ -881,23 +881,14 @@ func (s *Session) BuildFiles(filenames []string, pkgObj string, cwd string) erro
}

for _, file := range filenames {
if !strings.HasSuffix(file, ".inc.js") {
continue
}

content, err := os.ReadFile(file)
jsFile, err := incjs.FromFilename(file)
if err != nil {
return fmt.Errorf("failed to read %s: %w", file, err)
return err
}
info, err := os.Stat(file)
if err != nil {
return fmt.Errorf("failed to stat %s: %w", file, err)
if jsFile != nil {
jsFile.Path = filepath.Join(pkg.Dir, filepath.Base(file))
pkg.JSFiles = append(pkg.JSFiles, *jsFile)
}
pkg.JSFiles = append(pkg.JSFiles, jsFile.JSFile{
Path: filepath.Join(pkg.Dir, filepath.Base(file)),
ModTime: info.ModTime(),
Content: content,
})
}

archive, err := s.BuildProject(pkg)
Expand Down Expand Up @@ -1311,7 +1302,7 @@ func (s *Session) WaitForChange() {
if ev.Op&(fsnotify.Create|fsnotify.Write|fsnotify.Remove|fsnotify.Rename) == 0 || filepath.Base(ev.Name)[0] == '.' {
continue
}
if !strings.HasSuffix(ev.Name, ".go") && !strings.HasSuffix(ev.Name, ".inc.js") {
if !strings.HasSuffix(ev.Name, ".go") && !strings.HasSuffix(ev.Name, incjs.Ext) {
continue
}
s.options.PrintSuccess("change detected: %s\n", ev.Name)
Expand Down
7 changes: 4 additions & 3 deletions build/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
"strconv"
"testing"

"github.com/gopherjs/gopherjs/internal/srctesting"
"github.com/shurcooL/go/importgraphutil"

"github.com/gopherjs/gopherjs/internal/srctesting"
)

// Natives augment the standard library with GopherJS-specific changes.
Expand Down Expand Up @@ -254,7 +255,7 @@ func TestOverlayAugmentation(t *testing.T) {
src: `//gopherjs:purge
type (
Foo struct {}
bar interface{}
bar any
bob int
)`,
want: ``,
Expand All @@ -269,7 +270,7 @@ func TestOverlayAugmentation(t *testing.T) {
Foo struct {}

//gopherjs:purge
bar interface{}
bar any

//gopherjs:purge
bob int
Expand Down
3 changes: 2 additions & 1 deletion build/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import (
"path/filepath"
"time"

"github.com/gopherjs/gopherjs/compiler"
log "github.com/sirupsen/logrus"

"github.com/gopherjs/gopherjs/compiler"
)

// cacheRoot is the base path for GopherJS's own build cache.
Expand Down
1 change: 1 addition & 0 deletions build/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/google/go-cmp/cmp"

"github.com/gopherjs/gopherjs/compiler"
)

Expand Down
9 changes: 5 additions & 4 deletions build/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ import (
"sort"
"strings"

"golang.org/x/tools/go/buildutil"

_ "github.com/gopherjs/gopherjs/build/versionhack" // go/build release tags hack.
"github.com/gopherjs/gopherjs/compiler"
"github.com/gopherjs/gopherjs/compiler/gopherjspkg"
"github.com/gopherjs/gopherjs/compiler/jsFile"
"github.com/gopherjs/gopherjs/compiler/incjs"
"github.com/gopherjs/gopherjs/compiler/natives"
"golang.org/x/tools/go/buildutil"
)

// Env contains build environment configuration required to define an instance
Expand Down Expand Up @@ -91,9 +92,9 @@ func (sc simpleCtx) Import(importPath string, srcDir string, mode build.ImportMo
if err != nil {
return nil, err
}
jsFiles, err := jsFile.JSFilesFromDir(&sc.bctx, pkg.Dir)
jsFiles, err := incjs.FromDir(&sc.bctx, pkg.Dir)
if err != nil {
return nil, fmt.Errorf("failed to enumerate .inc.js files in %s: %w", pkg.Dir, err)
return nil, fmt.Errorf("failed to enumerate %s files in %s: %w", incjs.Ext, pkg.Dir, err)
}
if !path.IsAbs(pkg.Dir) {
pkg.Dir = mustAbs(pkg.Dir)
Expand Down
3 changes: 2 additions & 1 deletion build/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import (

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/gopherjs/gopherjs/compiler/gopherjspkg"
"golang.org/x/tools/go/buildutil"

"github.com/gopherjs/gopherjs/compiler/gopherjspkg"
)

func init() {
Expand Down
3 changes: 1 addition & 2 deletions build/versionhack/versionhack.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ package versionhack

import (
"go/build" // Must be initialized before this package.
_ "unsafe" // For go:linkname

"github.com/gopherjs/gopherjs/compiler"

_ "unsafe" // For go:linkname
)

//go:linkname releaseTags go/build.defaultReleaseTags
Expand Down
Loading
Loading