Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e908b92

Browse files
authored
fix(toImport): handle comma-separated declaration exports (#491)
* fix(toImport): handle comma-separated declaration exports * chore: disable lint in `playground/`
1 parent 6bbe5a7 commit e908b92

File tree

5 files changed

+17
-3
lines changed

5 files changed

+17
-3
lines changed

eslint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export default antfu(
55
pnpm: true,
66
ignores: [
77
'test/cases',
8+
'playground',
89
],
910
},
1011
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const FOO='foo',BAR='bar'

src/node/scan-dirs.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,10 @@ export async function scanExports(filepath: string, includeTypes: boolean, seen
138138
imports.push({ name, as: name, from: filepath, ...additional })
139139
}
140140
else if (exp.type === 'declaration') {
141-
if (exp.name) {
142-
imports.push({ name: exp.name, as: exp.name, from: filepath, ...additional })
141+
for (const name of exp.names) {
142+
imports.push({ name, as: name, from: filepath, ...additional })
143143
if (exp.declarationType === 'enum' || exp.declarationType === 'const enum' || exp.declarationType === 'class') {
144-
imports.push({ name: exp.name, as: exp.name, from: filepath, type: true, declarationType: exp.declarationType, ...additional })
144+
imports.push({ name, as: name, from: filepath, type: true, declarationType: exp.declarationType, ...additional })
145145
}
146146
}
147147
}

test/dts.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ it('dts', async () => {
6868
"export {}
6969
declare global {
7070
const $: typeof import('jquery').$
71+
const BAR: typeof import('<root>/playground/composables/comma-separated').BAR
7172
const CustomEnum: typeof import('<root>/playground/composables/index').CustomEnum
73+
const FOO: typeof import('<root>/playground/composables/comma-separated').FOO
7274
const PascalCased: typeof import('<root>/playground/composables/PascalCased').PascalCased
7375
const THREE: typeof import('three')
7476
const bar: typeof import('<root>/playground/composables/nested/bar/index').bar

test/scan-dirs.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ describe('scan-dirs', () => {
1414
)
1515
.toMatchInlineSnapshot(`
1616
[
17+
{
18+
"as": "BAR",
19+
"from": "comma-separated.ts",
20+
"name": "BAR",
21+
},
1722
{
1823
"as": "bump",
1924
"from": "index.ts",
@@ -48,6 +53,11 @@ describe('scan-dirs', () => {
4853
"from": "foo.ts",
4954
"name": "default",
5055
},
56+
{
57+
"as": "FOO",
58+
"from": "comma-separated.ts",
59+
"name": "FOO",
60+
},
5161
{
5262
"as": "localA",
5363
"from": "index.ts",

0 commit comments

Comments
 (0)