Skip to content

Commit 092cdd9

Browse files
authored
fix(interop): only passthrough default if it is not a promise (#408)
1 parent 037c646 commit 092cdd9

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ function interopDefault(mod: any): any {
135135
if (Reflect.has(target, prop)) {
136136
return Reflect.get(target, prop, receiver);
137137
}
138-
if (defIsObj) {
138+
if (defIsObj && !((def instanceof Promise) /** issue: #400 */)) {
139139
let fallback = Reflect.get(def, prop, receiver);
140140
if (typeof fallback === "function") {
141141
fallback = fallback.bind(def);

test/__snapshots__/fixtures.test.ts.snap

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ exports[`fixtures > esm > stdout 1`] = `
5555
}"
5656
`;
5757

58+
exports[`fixtures > export-promise > stdout 1`] = `
59+
"module: [Module: null prototype] {
60+
bar: 'bar',
61+
default: Promise { 'foo' },
62+
foo: [AsyncFunction: foo]
63+
}
64+
default module: foo"
65+
`;
66+
5867
exports[`fixtures > hashbang > stdout 1`] = `"1"`;
5968

6069
exports[`fixtures > import-map > stdout 1`] = `"{ alias: 'alias' }"`;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const foo = async () => "foo";
2+
export const bar = "bar";
3+
4+
export default foo();
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { createJiti } from "../../../lib/jiti.cjs";
2+
3+
async function main() {
4+
const jiti = createJiti(import.meta.url);
5+
6+
const mod = await jiti.import("./export-promise.mjs", { default: false });
7+
console.log("module:", mod);
8+
9+
const defaultMod = await jiti.import("./export-promise.mjs", {
10+
default: true,
11+
});
12+
console.log("default module:", defaultMod);
13+
}
14+
15+
main().catch((error_) => {
16+
console.error("Error:", error_);
17+
});

0 commit comments

Comments
 (0)