diff --git a/go.mod b/go.mod index 991dedb7df6..79a48263575 100644 --- a/go.mod +++ b/go.mod @@ -75,7 +75,7 @@ require ( github.com/go-logr/stdr v1.2.2 // indirect github.com/google/pprof v0.0.0-20230728192033-2ba5b33183c6 // indirect github.com/google/uuid v1.6.0 // indirect - github.com/grafana/sobek v0.0.0-20240708142253-1d1dbd360a51 + github.com/grafana/sobek v0.0.0-20240711133011-3a280d337ef4 github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/josharian/intern v1.0.0 // indirect diff --git a/go.sum b/go.sum index 78a8ed8fe68..f32e427127d 100644 --- a/go.sum +++ b/go.sum @@ -82,8 +82,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= -github.com/grafana/sobek v0.0.0-20240708142253-1d1dbd360a51 h1:OqNtCMYUW2mEg5Ang0zMAeuexLSeqoOEVi/MufZXfBI= -github.com/grafana/sobek v0.0.0-20240708142253-1d1dbd360a51/go.mod h1:tUEHKWaMrxFGrMgjeAH85OEceCGQiSl6a/6Wckj/Vf4= +github.com/grafana/sobek v0.0.0-20240711133011-3a280d337ef4 h1:SKC348XXnCe9EIsAJ+xs5lzlZbzRsrGkqVbJ3451p3k= +github.com/grafana/sobek v0.0.0-20240711133011-3a280d337ef4/go.mod h1:tUEHKWaMrxFGrMgjeAH85OEceCGQiSl6a/6Wckj/Vf4= github.com/grafana/xk6-browser v1.6.1-0.20240701105714-29f6ef3049fe h1:uE7e1Lzris7YuM5mRLulkUGBIL9WmPHvLrA2RyZLyy8= github.com/grafana/xk6-browser v1.6.1-0.20240701105714-29f6ef3049fe/go.mod h1:TNngUsbmV3I5NDVklGxjpAR2znEjYEsBtHQirGw8nAI= github.com/grafana/xk6-dashboard v0.7.5 h1:TcILyffT/Ea/XD7xG1jMA5lwtusOPRbEQsQDHmO30Mk= diff --git a/vendor/github.com/grafana/sobek/README.md b/vendor/github.com/grafana/sobek/README.md index 030278f50fd..dd5d23ff9aa 100644 --- a/vendor/github.com/grafana/sobek/README.md +++ b/vendor/github.com/grafana/sobek/README.md @@ -23,10 +23,23 @@ Features * Capable of running Babel, Typescript compiler and pretty much anything written in ES5. * Sourcemaps. * Most of ES6 functionality, still work in progress, see https://github.com/grafana/sobek/milestone/1?closed=1 + * Experimental ESM support. Known incompatibilities and caveats ----------------------------------- +### ESM support + +ECMAScript Modules or ESM for short was implemented and merged in this fork to facilitate the needs of [k6](https://github.com/grafana/k6/) as such some compromises were taken in favor of time. + +In general the API is very close to the specification, which unfortunately does *not* translate greatly to actual usage. + +For this reason it is very likely that it will be updated in breaking manner in the future and there is currently no concrete documentation around it. + +For any usage info or bare documentation it is recommended to look at the tests in [modules_test.go](https://github.com/grafana/sobek/blob/main/modules_test.go) and [modules_integration_test.go](https://github.com/grafana/sobek/blob/main/modules_integration_test.go). + +Also of note is that due to the nature of ESM you need to have an event loop implementation to use it. That is still not provided by Sobek and likely never will be. + ### WeakMap WeakMap is implemented by embedding references to the values into the keys. This means that as long as the key is reachable all values associated with it in any weak maps also remain reachable and therefore @@ -132,7 +145,6 @@ do not just base it on a couple of examples that work fine. Current Status -------------- - * There should be no breaking changes in the API, however it may be extended. * Some of the AnnexB functionality is missing. Basic Example diff --git a/vendor/github.com/grafana/sobek/compiler.go b/vendor/github.com/grafana/sobek/compiler.go index 946a67b84aa..7fbd91ba4ea 100644 --- a/vendor/github.com/grafana/sobek/compiler.go +++ b/vendor/github.com/grafana/sobek/compiler.go @@ -977,7 +977,7 @@ func (c *compiler) compileModule(module *SourceTextModuleRecord) { for _, in := range module.indirectExportEntries { v, ambiguous := module.ResolveExport(in.exportName) if v == nil || ambiguous { - c.compileAmbiguousImport(unistring.NewFromString(in.importName)) + c.compileImportError(ambiguous, in.moduleRequest, in.exportName, in.offset) } } @@ -1057,7 +1057,7 @@ func (c *compiler) compileImportEntry(in importEntry) { if in.importName != "*" { resolution, ambiguous := importedModule.ResolveExport(in.importName) if resolution == nil || ambiguous { - c.compileAmbiguousImport(unistring.NewFromString(in.importName)) + c.compileImportError(ambiguous, in.moduleRequest, in.importName, in.offset) return } } @@ -1102,7 +1102,7 @@ func (c *compiler) compileIndirectExportEntry(entry exportEntry) { } b, ambiguous := otherModule.ResolveExport(entry.importName) if ambiguous || b == nil { - c.compileAmbiguousImport(unistring.NewFromString(entry.importName)) + c.compileImportError(ambiguous, entry.moduleRequest, entry.importName, entry.offset) return } @@ -1213,8 +1213,23 @@ func (c *compiler) compile(in *ast.Program, strict, inGlobal bool, evalVm *vm) { c.stringCache = nil } -func (c *compiler) compileAmbiguousImport(name unistring.String) { - c.emit(ambiguousImport(name)) +func (c *compiler) compileImportError(ambiguous bool, module, identifier string, offset int) { + if ambiguous { + c.compileSyntaxError( + fmt.Sprintf("The requested module %q contains conflicting star exports for name %q", + module, identifier), + offset) + } else { + c.compileSyntaxError( + fmt.Sprintf("The requested module %q does not provide an export named %q", + module, identifier), + offset) + } +} + +func (c *compiler) compileSyntaxError(msg string, offset int) { + c.p.addSrcMap(offset) + c.emit(runtimeSyntaxError(msg)) } func (c *compiler) compileDeclList(v []*ast.VariableDeclaration, inFunc bool) { diff --git a/vendor/github.com/grafana/sobek/vm.go b/vendor/github.com/grafana/sobek/vm.go index d63bacf7c6a..6830913ccb7 100644 --- a/vendor/github.com/grafana/sobek/vm.go +++ b/vendor/github.com/grafana/sobek/vm.go @@ -3957,10 +3957,10 @@ func (n *newArrowFunc) _exec(vm *vm, obj *arrowFuncObject) { vm.pc++ } -type ambiguousImport unistring.String +type runtimeSyntaxError string -func (a ambiguousImport) exec(vm *vm) { - panic(vm.r.newError(vm.r.getSyntaxError(), "Ambiguous import for name %s", a)) +func (a runtimeSyntaxError) exec(vm *vm) { + panic(vm.r.newError(vm.r.getSyntaxError(), (string)(a))) } func (n *newArrowFunc) exec(vm *vm) { diff --git a/vendor/modules.txt b/vendor/modules.txt index 346762c81ba..f30d78e02e7 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -163,7 +163,7 @@ github.com/google/uuid # github.com/gorilla/websocket v1.5.1 ## explicit; go 1.20 github.com/gorilla/websocket -# github.com/grafana/sobek v0.0.0-20240708142253-1d1dbd360a51 +# github.com/grafana/sobek v0.0.0-20240711133011-3a280d337ef4 ## explicit; go 1.20 github.com/grafana/sobek github.com/grafana/sobek/ast