Skip to content

Commit

Permalink
Return either Default or Named exports early
Browse files Browse the repository at this point in the history
Co-authored-by: Mihail Stoykov <M.Stoikov@gmail.com>

See #2108 (comment)
  • Loading branch information
Ivan Mirić committed Aug 6, 2021
1 parent 409c457 commit da1fb43
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion js/initcontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down

0 comments on commit da1fb43

Please sign in to comment.