diff --git a/lib/register.js b/lib/register.js index 9c06cb3..2de012b 100644 --- a/lib/register.js +++ b/lib/register.js @@ -17,7 +17,12 @@ const proxyHandler = { if (name === Symbol.toStringTag) { return 'Module' } - return getters.get(target)[name]() + + const getter = getters.get(target)[name] + + if (typeof getter === 'function') { + return getter() + } }, defineProperty (target, property, descriptor) { diff --git a/test/hook/v14-double-hook.mjs b/test/hook/v14-double-hook.mjs index feb997c..2098e69 100644 --- a/test/hook/v14-double-hook.mjs +++ b/test/hook/v14-double-hook.mjs @@ -19,6 +19,15 @@ Hook([toWrap], (exports) => { } }) -const { foo } = await import('../fixtures/foo.mjs') +Hook([toWrap], (exports) => { + const shouldNotExist = exports.default + exports = function () { + return shouldNotExist() + } +}) + +const imp = await import('../fixtures/foo.mjs') -strictEqual(foo(), 'foo-first-second') +strictEqual(imp.foo(), 'foo-first-second') +// This should not throw! +strictEqual(imp.default, undefined)