Skip to content

Commit 03e59cb

Browse files
committed
chore: wip
chore: wip chore: wip
1 parent 4704436 commit 03e59cb

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/extract.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const DEBUG = true // Set to false to disable debug logs
22

3-
function logDebug(...messages: any[]): void {
3+
function logDebug(...messages: unknown[]): void {
44
if (DEBUG) {
55
console.log(...messages)
66
}
@@ -103,6 +103,9 @@ function processDeclaration(declaration: string): string {
103103
else if (declaration.startsWith('interface')) {
104104
return processInterfaceDeclaration(declaration)
105105
}
106+
else if (declaration.startsWith('export type {')) {
107+
return processTypeOnlyExport(declaration)
108+
}
106109
else if (declaration.startsWith('export type')) {
107110
return processTypeDeclaration(declaration)
108111
}
@@ -176,12 +179,18 @@ function processInterfaceDeclaration(declaration: string): string {
176179
return result
177180
}
178181

182+
function processTypeOnlyExport(declaration: string): string {
183+
logDebug(`Processing type-only export: ${declaration}`)
184+
return declaration.replace('export type', 'export declare type')
185+
}
186+
179187
function processTypeDeclaration(declaration: string): string {
180188
logDebug(`Processing type declaration: ${declaration}`)
181189
const lines = declaration.split('\n')
182-
const typeName = lines[0].split('type')[1].split('=')[0].trim()
183-
const typeBody = lines.slice(1).join('\n').trim().replace(/;$/, '')
184-
const result = `export declare type ${typeName} = ${typeBody}`
190+
const firstLine = lines[0]
191+
const typeName = firstLine.split('type')[1].split('=')[0].trim()
192+
const typeBody = firstLine.split('=')[1]?.trim() || lines.slice(1).join('\n').trim().replace(/;$/, '')
193+
const result = `export declare type ${typeName} = ${typeBody};`
185194
logDebug(`Processed type declaration: ${result}`)
186195
return result
187196
}

0 commit comments

Comments
 (0)