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

Skip to content

Commit f0172aa

Browse files
polishing code
1 parent 74b2aec commit f0172aa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+385
-289
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ package main
125125
import "github.com/gopherjs/gopherjs/js"
126126

127127
func main() {
128-
js.Global.Set("pet", map[string]interface{}{
128+
js.Global.Set("pet", map[string]any{
129129
"New": New,
130130
})
131131
}

build/build.go

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ import (
2525
"time"
2626

2727
"github.com/fsnotify/fsnotify"
28+
"github.com/neelance/sourcemap"
29+
log "github.com/sirupsen/logrus"
30+
"golang.org/x/tools/go/buildutil"
31+
2832
"github.com/gopherjs/gopherjs/compiler"
2933
"github.com/gopherjs/gopherjs/compiler/astutil"
30-
"github.com/gopherjs/gopherjs/compiler/jsFile"
34+
"github.com/gopherjs/gopherjs/compiler/incjs"
3135
"github.com/gopherjs/gopherjs/compiler/sources"
32-
"github.com/gopherjs/gopherjs/internal/errorList"
36+
"github.com/gopherjs/gopherjs/internal/errlist"
3337
"github.com/gopherjs/gopherjs/internal/testmain"
34-
log "github.com/sirupsen/logrus"
35-
36-
"github.com/neelance/sourcemap"
37-
"golang.org/x/tools/go/buildutil"
3838
)
3939

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

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

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

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

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

883883
for _, file := range filenames {
884-
if !strings.HasSuffix(file, ".inc.js") {
885-
continue
886-
}
887-
888-
content, err := os.ReadFile(file)
884+
jsFile, err := incjs.FromFilename(file)
889885
if err != nil {
890-
return fmt.Errorf("failed to read %s: %w", file, err)
886+
return err
891887
}
892-
info, err := os.Stat(file)
893-
if err != nil {
894-
return fmt.Errorf("failed to stat %s: %w", file, err)
888+
if jsFile != nil {
889+
jsFile.Path = filepath.Join(pkg.Dir, filepath.Base(file))
890+
pkg.JSFiles = append(pkg.JSFiles, *jsFile)
895891
}
896-
pkg.JSFiles = append(pkg.JSFiles, jsFile.JSFile{
897-
Path: filepath.Join(pkg.Dir, filepath.Base(file)),
898-
ModTime: info.ModTime(),
899-
Content: content,
900-
})
901892
}
902893

903894
archive, err := s.BuildProject(pkg)
@@ -1311,7 +1302,7 @@ func (s *Session) WaitForChange() {
13111302
if ev.Op&(fsnotify.Create|fsnotify.Write|fsnotify.Remove|fsnotify.Rename) == 0 || filepath.Base(ev.Name)[0] == '.' {
13121303
continue
13131304
}
1314-
if !strings.HasSuffix(ev.Name, ".go") && !strings.HasSuffix(ev.Name, ".inc.js") {
1305+
if !strings.HasSuffix(ev.Name, ".go") && !strings.HasSuffix(ev.Name, incjs.Ext) {
13151306
continue
13161307
}
13171308
s.options.PrintSuccess("change detected: %s\n", ev.Name)

build/build_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import (
77
"strconv"
88
"testing"
99

10-
"github.com/gopherjs/gopherjs/internal/srctesting"
1110
"github.com/shurcooL/go/importgraphutil"
11+
12+
"github.com/gopherjs/gopherjs/internal/srctesting"
1213
)
1314

1415
// Natives augment the standard library with GopherJS-specific changes.
@@ -254,7 +255,7 @@ func TestOverlayAugmentation(t *testing.T) {
254255
src: `//gopherjs:purge
255256
type (
256257
Foo struct {}
257-
bar interface{}
258+
bar any
258259
bob int
259260
)`,
260261
want: ``,
@@ -269,7 +270,7 @@ func TestOverlayAugmentation(t *testing.T) {
269270
Foo struct {}
270271
271272
//gopherjs:purge
272-
bar interface{}
273+
bar any
273274
274275
//gopherjs:purge
275276
bob int

build/cache/cache.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ import (
1212
"path/filepath"
1313
"time"
1414

15-
"github.com/gopherjs/gopherjs/compiler"
1615
log "github.com/sirupsen/logrus"
16+
17+
"github.com/gopherjs/gopherjs/compiler"
1718
)
1819

1920
// cacheRoot is the base path for GopherJS's own build cache.

build/cache/cache_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"time"
77

88
"github.com/google/go-cmp/cmp"
9+
910
"github.com/gopherjs/gopherjs/compiler"
1011
)
1112

build/context.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ import (
1212
"sort"
1313
"strings"
1414

15+
"golang.org/x/tools/go/buildutil"
16+
1517
_ "github.com/gopherjs/gopherjs/build/versionhack" // go/build release tags hack.
1618
"github.com/gopherjs/gopherjs/compiler"
1719
"github.com/gopherjs/gopherjs/compiler/gopherjspkg"
18-
"github.com/gopherjs/gopherjs/compiler/jsFile"
20+
"github.com/gopherjs/gopherjs/compiler/incjs"
1921
"github.com/gopherjs/gopherjs/compiler/natives"
20-
"golang.org/x/tools/go/buildutil"
2122
)
2223

2324
// Env contains build environment configuration required to define an instance
@@ -91,9 +92,9 @@ func (sc simpleCtx) Import(importPath string, srcDir string, mode build.ImportMo
9192
if err != nil {
9293
return nil, err
9394
}
94-
jsFiles, err := jsFile.JSFilesFromDir(&sc.bctx, pkg.Dir)
95+
jsFiles, err := incjs.FromDir(&sc.bctx, pkg.Dir)
9596
if err != nil {
96-
return nil, fmt.Errorf("failed to enumerate .inc.js files in %s: %w", pkg.Dir, err)
97+
return nil, fmt.Errorf("failed to enumerate %s files in %s: %w", incjs.Ext, pkg.Dir, err)
9798
}
9899
if !path.IsAbs(pkg.Dir) {
99100
pkg.Dir = mustAbs(pkg.Dir)

build/context_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import (
1010

1111
"github.com/google/go-cmp/cmp"
1212
"github.com/google/go-cmp/cmp/cmpopts"
13-
"github.com/gopherjs/gopherjs/compiler/gopherjspkg"
1413
"golang.org/x/tools/go/buildutil"
14+
15+
"github.com/gopherjs/gopherjs/compiler/gopherjspkg"
1516
)
1617

1718
func init() {

build/versionhack/versionhack.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ package versionhack
2828

2929
import (
3030
"go/build" // Must be initialized before this package.
31+
_ "unsafe" // For go:linkname
3132

3233
"github.com/gopherjs/gopherjs/compiler"
33-
34-
_ "unsafe" // For go:linkname
3534
)
3635

3736
//go:linkname releaseTags go/build.defaultReleaseTags

0 commit comments

Comments
 (0)