Skip to content

Commit

Permalink
fix: unjs#318
Browse files Browse the repository at this point in the history
  • Loading branch information
tmg0 committed Feb 6, 2024
1 parent d9bcb9a commit cb8a979
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions playground/composables/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ export type CustomType1 = string | number
export interface CustomInterface1 {
name: string
}

export enum CustomEnum {}
9 changes: 8 additions & 1 deletion src/node/scan-dirs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ export function dedupeDtsExports(exports: Import[]) {
if (!i.type)
return true

// import enum as both value and type
if (i.declaration === 'enum')
return true

return !exports.find(e => e.as === i.as && e.name === i.name && !e.type)
})
}
Expand Down Expand Up @@ -95,8 +99,11 @@ export async function scanExports(filepath: string, includeTypes: boolean, seen
imports.push({ name, as: name, from: filepath, ...additional })
}
else if (exp.type === 'declaration') {
if (exp.name)
if (exp.name) {
imports.push({ name: exp.name, as: exp.name, from: filepath, ...additional })
if (exp.declaration === 'enum')
imports.push({ name: exp.name, as: exp.name, from: filepath, type: true, declaration: exp.declaration, ...additional })
}
}
else if (exp.type === 'star' && exp.specifier) {
if (exp.name) {
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export interface ImportCommon {
disabled?: boolean
/** Won't output import in declaration file if true */
dtsDisabled?: boolean
/** Import declaration like const / var / enum */
declaration?: string
/**
* Metadata of the import
*/
Expand Down
1 change: 1 addition & 0 deletions test/dts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ it('dts', async () => {
"export {}
declare global {
const $: typeof import('jquery')['$']
const CustomEnum: typeof import('<root>/playground/composables/index')['CustomEnum']
const PascalCased: typeof import('<root>/playground/composables/PascalCased')['PascalCased']
const THREE: typeof import('three')
const bar: typeof import('<root>/playground/composables/nested/bar/index')['bar']
Expand Down
12 changes: 12 additions & 0 deletions test/scan-dirs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ describe('scan-dirs', () => {
"from": "index.ts",
"name": "bump",
},
{
"as": "CustomEnum",
"from": "index.ts",
"name": "CustomEnum",
},
{
"as": "CustomEnum",
"declaration": "enum",
"from": "index.ts",
"name": "CustomEnum",
"type": true,
},
{
"as": "CustomInterface1",
"from": "index.ts",
Expand Down

0 comments on commit cb8a979

Please sign in to comment.