feat(dedupeImports): preserve imports with same `from` and `name`, bu… · unjs/unimport@c340f33 · GitHub
Skip to content

Commit c340f33

Browse files
authored
feat(dedupeImports): preserve imports with same from and name, but different type (#507)
* fix(dedupeImports): preserve imports array indexes * test(dedupeImports): correctly dedupe imports when some are disabled * perf(dedupeImports): use single map and for...of, and reduce iterations and lookups * feat(dedupeImports): do not deduplicate complementary value and type imports * test(dts): generate value and type declarations for complementary imports
1 parent c6e84f6 commit c340f33

3 files changed

Lines changed: 118 additions & 23 deletions

File tree

src/utils.ts

Lines changed: 57 additions & 23 deletions

test/dedupe.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,39 @@ describe('dedupeImports', () => {
6767
`)
6868
})
6969

70+
it('should not dedupe disabled imports', () => {
71+
const imports = [
72+
{
73+
name: 'foo',
74+
from: 'moduleA',
75+
disabled: true,
76+
},
77+
{
78+
name: 'foo',
79+
from: 'moduleB',
80+
},
81+
{
82+
name: 'foo',
83+
from: 'moduleC',
84+
},
85+
]
86+
87+
expect(dedupeImports(imports, warnFn)).toMatchInlineSnapshot(`
88+
[
89+
{
90+
"disabled": true,
91+
"from": "moduleA",
92+
"name": "foo",
93+
},
94+
{
95+
"from": "moduleC",
96+
"name": "foo",
97+
},
98+
]
99+
`)
100+
expect(warnMsg).toMatchInlineSnapshot(`"Duplicated imports "foo", the one from "moduleB" has been ignored and "moduleC" is used"`)
101+
})
102+
70103
it('should not warn about duplicates when one is disabled', () => {
71104
expect(dedupeImports(
72105
[

test/dts.test.ts

Lines changed: 28 additions & 0 deletions

0 commit comments

Comments
 (0)