Skip to content

Commit

Permalink
refactor(interopDefault): simplify implementation (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Apr 30, 2024
1 parent ae0129b commit 74dcba9
Showing 1 changed file with 11 additions and 25 deletions.
36 changes: 11 additions & 25 deletions src/cjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,31 +51,17 @@ export function interopDefault(
return opts.preferNamespace ? sourceModule : defaultValue;
}
for (const key in sourceModule) {
if (key === "default") {
try {
if (!(key in defaultValue)) {
Object.defineProperty(defaultValue, key, {
enumerable: false,
configurable: false,
get() {
return defaultValue;
},
});
}
} catch {}
} else {
try {
if (!(key in defaultValue)) {
Object.defineProperty(defaultValue, key, {
enumerable: true,
configurable: true,
get() {
return sourceModule[key];
},
});
}
} catch {}
}
try {
if (!(key in defaultValue)) {
Object.defineProperty(defaultValue, key, {
enumerable: key !== "default",
configurable: key !== "default",
get() {
return sourceModule[key];
},
});
}
} catch {}
}
return defaultValue;
}

0 comments on commit 74dcba9

Please sign in to comment.