Skip to content

Commit

Permalink
Refactor back to if/else instead of switch
Browse files Browse the repository at this point in the history
  • Loading branch information
ankur22 committed Nov 15, 2024
1 parent 5a06291 commit ee913c5
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions js/modules/gomodule.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@ func (gm *goModule) Instantiate(rt *sobek.Runtime) (sobek.CyclicModuleInstance,
if gm.exportedNames == nil {
named := mi.Exports().Named

switch {
case named == nil && mi.Exports().Default != nil:
if named == nil && mi.Exports().Default != nil {
// If named length is 0 but default is defined, then try to work with
// default and extract the names of the object's properties. This
// behavior isn't ESM compatible, but we do want to allow defaults to
// be imported as namespaced object, which is also how node works.
obj := rt.ToValue(mi.Exports().Default).ToObject(rt)
gm.exportedNames = obj.GetOwnPropertyNames()
default:
} else {
gm.exportedNames = make([]string, 0, len(named))
for name := range named {
gm.exportedNames = append(gm.exportedNames, name)
Expand Down

0 comments on commit ee913c5

Please sign in to comment.