Skip to content

Commit

Permalink
fix(interopDefault): do not override existing props (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Oct 12, 2021
1 parent 4430fe3 commit 9429606
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions lib/index.mjs
Expand Up @@ -115,19 +115,23 @@ export function interopDefault (sourceModule) {
for (const key in sourceModule) {
if (key === 'default') {
try {
Object.defineProperty(newModule, key, {
enumerable: false,
configurable: false,
get () { return newModule }
})
if (!(key in newModule)) {
Object.defineProperty(newModule, key, {
enumerable: false,
configurable: false,
get () { return newModule }
})
}
} catch (_err) {}
} else {
try {
Object.defineProperty(newModule, key, {
enumerable: true,
configurable: true,
get () { return sourceModule[key] }
})
if (!(key in newModule)) {
Object.defineProperty(newModule, key, {
enumerable: true,
configurable: true,
get () { return sourceModule[key] }
})
}
} catch (_err) {}
}
}
Expand Down

0 comments on commit 9429606

Please sign in to comment.