Skip to content

Commit 1b9fcab

Browse files
TheAlexLichterpi0
andauthored
fix: merge objects with Module type (#121)
Co-authored-by: Pooya Parsa <[email protected]>
1 parent 7c7a9a4 commit 1b9fcab

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

src/_utils.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@ export function isPlainObject(value: unknown): boolean {
1414
return false;
1515
}
1616

17-
if (Symbol.toStringTag in value || Symbol.iterator in value) {
17+
if (Symbol.iterator in value) {
1818
return false;
1919
}
2020

21+
if (Symbol.toStringTag in value) {
22+
return Object.prototype.toString.call(value) === "[object Module]";
23+
}
24+
2125
return true;
2226
}

test/defu.test.ts

+18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { expectTypeOf } from "expect-type";
22
import { it, describe, expect } from "vitest";
33
import { defu, createDefu, defuFn, defuArrayFn } from "../src/defu";
4+
import * as asteriskImport from "./fixtures/";
45

56
// Part of tests brought from jonschlinkert/defaults-deep (MIT)
67
const nonObject = [null, undefined, [], false, true, 123];
@@ -232,4 +233,21 @@ describe("defu", () => {
232233
foo: { bar: { modules: "foo.bar:X,Y" } },
233234
});
234235
});
236+
237+
it("works with asterisk-import", () => {
238+
expect(
239+
defu(asteriskImport, {
240+
a: 2,
241+
exp: {
242+
anotherNested: 2,
243+
},
244+
}),
245+
).toStrictEqual({
246+
a: 2,
247+
exp: {
248+
anotherNested: 2,
249+
nested: 1,
250+
},
251+
});
252+
});
235253
});

test/fixtures/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as exp } from "./nested.js";

test/fixtures/nested.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default {
2+
nested: 1,
3+
};

0 commit comments

Comments
 (0)