Skip to content

Commit

Permalink
fix: do nothing if target does not exist in getters map (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
karrui authored Sep 30, 2024
1 parent 901b8b1 commit 5f6be49
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
7 changes: 6 additions & 1 deletion lib/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 11 additions & 2 deletions test/hook/v14-double-hook.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 5f6be49

Please sign in to comment.