diff --git a/js/bundle.go b/js/bundle.go index 68c953b558f..9a9f2104099 100644 --- a/js/bundle.go +++ b/js/bundle.go @@ -38,7 +38,7 @@ type Bundle struct { pwd *url.URL callableExports map[string]struct{} - modResolution *modulesResolution + moduleResolver *moduleResolver } // A BundleInstance is a self-contained instance of a Bundle. @@ -85,14 +85,14 @@ func newBundle( Options: options, CompatibilityMode: compatMode, callableExports: make(map[string]struct{}), - modResolution: newModuleResolution(getJSModules()), + moduleResolver: newModuleResolution(getJSModules()), filesystems: filesystems, pwd: loader.Dir(src.URL), logger: piState.Logger, preInitState: piState, } c := bundle.newCompiler(piState.Logger) - if err = bundle.modResolution.setMain(src, c); err != nil { + if err = bundle.moduleResolver.setMain(src, c); err != nil { return nil, err } // Instantiate the bundle into a new VM using a bound init context. This uses a context with a @@ -274,7 +274,7 @@ func (b *Bundle) instantiate(vuImpl *moduleVUImpl, vuID uint64, c *compiler.Comp } cjsLoad := generateCJSLoad(b, c) - modSys := newModuleSystem(b.modResolution, vuImpl, cjsLoad) + modSys := newModuleSystem(b.moduleResolver, vuImpl, cjsLoad) unbindInit := b.setInitGlobals(rt, modSys) vuImpl.initEnv = initenv defer func() { @@ -298,7 +298,7 @@ func (b *Bundle) instantiate(vuImpl *moduleVUImpl, vuID uint64, c *compiler.Comp err = common.RunWithPanicCatching(b.logger, rt, func() error { return vuImpl.eventLoop.Start(func() error { //nolint:shadow,govet // here we shadow err on purpose - mod, err := b.modResolution.resolve(b.pwd, b.Filename.String(), cjsLoad) + mod, err := b.moduleResolver.resolve(b.pwd, b.Filename.String(), cjsLoad) if err != nil { return err // TODO wrap as this should never happen } diff --git a/js/modules.go b/js/modules.go index 06e2c954e47..d694125ed39 100644 --- a/js/modules.go +++ b/js/modules.go @@ -24,22 +24,22 @@ type moduleCacheElement struct { err error } -type modulesResolution struct { +type moduleResolver struct { cache map[string]moduleCacheElement goModules map[string]interface{} } -func newModuleResolution(goModules map[string]interface{}) *modulesResolution { - return &modulesResolution{goModules: goModules, cache: make(map[string]moduleCacheElement)} +func newModuleResolution(goModules map[string]interface{}) *moduleResolver { + return &moduleResolver{goModules: goModules, cache: make(map[string]moduleCacheElement)} } -func (mr *modulesResolution) setMain(main *loader.SourceData, c *compiler.Compiler) error { +func (mr *moduleResolver) setMain(main *loader.SourceData, c *compiler.Compiler) error { mod, err := cjsmoduleFromString(main.URL, main.Data, c) mr.cache[main.URL.String()] = moduleCacheElement{mod: mod, err: err} return err } -func (mr *modulesResolution) resolveSpecifier(basePWD *url.URL, arg string) (*url.URL, error) { +func (mr *moduleResolver) resolveSpecifier(basePWD *url.URL, arg string) (*url.URL, error) { specifier, err := loader.Resolve(basePWD, arg) if err != nil { return nil, err @@ -47,7 +47,7 @@ func (mr *modulesResolution) resolveSpecifier(basePWD *url.URL, arg string) (*ur return specifier, nil } -func (mr *modulesResolution) requireModule(name string) (module, error) { +func (mr *moduleResolver) requireModule(name string) (module, error) { mod, ok := mr.goModules[name] if !ok { return nil, fmt.Errorf("unknown module: %s", name) @@ -59,7 +59,7 @@ func (mr *modulesResolution) requireModule(name string) (module, error) { return &baseGoModule{mod: mod}, nil } -func (mr *modulesResolution) resolve(basePWD *url.URL, arg string, loadCJS cjsModuleLoader) (module, error) { +func (mr *moduleResolver) resolve(basePWD *url.URL, arg string, loadCJS cjsModuleLoader) (module, error) { if cached, ok := mr.cache[arg]; ok { return cached.mod, cached.err } @@ -89,13 +89,13 @@ func (mr *modulesResolution) resolve(basePWD *url.URL, arg string, loadCJS cjsMo type moduleSystem struct { vu modules.VU instanceCache map[module]moduleInstance - resolution *modulesResolution + resolver *moduleResolver cjsLoad cjsModuleLoader } -func newModuleSystem(resolution *modulesResolution, vu modules.VU, cjsLoad cjsModuleLoader) *moduleSystem { +func newModuleSystem(resolution *moduleResolver, vu modules.VU, cjsLoad cjsModuleLoader) *moduleSystem { return &moduleSystem{ - resolution: resolution, + resolver: resolution, instanceCache: make(map[module]moduleInstance), vu: vu, cjsLoad: cjsLoad, @@ -104,7 +104,7 @@ func newModuleSystem(resolution *modulesResolution, vu modules.VU, cjsLoad cjsMo // Require is called when a module/file needs to be loaded by a script func (ms *moduleSystem) Require(pwd *url.URL, arg string) (*goja.Object, error) { - mod, err := ms.resolution.resolve(pwd, arg, ms.cjsLoad) + mod, err := ms.resolver.resolve(pwd, arg, ms.cjsLoad) if err != nil { return nil, err }