Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do nothing if target does not exist in getters map #155

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading