From da1fb43c1c424113e2d50dfe7b5582a4f546b220 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Miri=C4=87?= Date: Fri, 6 Aug 2021 16:53:25 +0200 Subject: [PATCH] Return either Default or Named exports early Co-authored-by: Mihail Stoykov See https://github.com/grafana/k6/pull/2108#discussion_r684278734 --- js/initcontext.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/js/initcontext.go b/js/initcontext.go index b12c0e85aaf..e6df1bd8ec7 100644 --- a/js/initcontext.go +++ b/js/initcontext.go @@ -171,7 +171,14 @@ func (m *moduleInstanceCoreImpl) GetRuntime() *goja.Runtime { return common.GetRuntime(*m.ctxPtr) // TODO thread it correctly instead } -func toESModuleExports(exp modules.Exports) map[string]interface{} { +func toESModuleExports(exp modules.Exports) interface{} { + if exp.Named == nil { + return exp.Default + } + if exp.Default == nil { + return exp.Named + } + result := make(map[string]interface{}, len(exp.Named)+2) for k, v := range exp.Named { @@ -180,6 +187,7 @@ func toESModuleExports(exp modules.Exports) map[string]interface{} { // Maybe check that those weren't set result["default"] = exp.Default result["__esModule"] = true // this so babel works with + return result }