Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
chore: wip

chore: wip
  • Loading branch information
chrisbbreuer committed Oct 21, 2024
1 parent 4704436 commit 03e59cb
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/extract.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const DEBUG = true // Set to false to disable debug logs

function logDebug(...messages: any[]): void {
function logDebug(...messages: unknown[]): void {
if (DEBUG) {
console.log(...messages)
}
Expand Down Expand Up @@ -103,6 +103,9 @@ function processDeclaration(declaration: string): string {
else if (declaration.startsWith('interface')) {
return processInterfaceDeclaration(declaration)
}
else if (declaration.startsWith('export type {')) {
return processTypeOnlyExport(declaration)
}
else if (declaration.startsWith('export type')) {
return processTypeDeclaration(declaration)
}
Expand Down Expand Up @@ -176,12 +179,18 @@ function processInterfaceDeclaration(declaration: string): string {
return result
}

function processTypeOnlyExport(declaration: string): string {
logDebug(`Processing type-only export: ${declaration}`)
return declaration.replace('export type', 'export declare type')
}

function processTypeDeclaration(declaration: string): string {
logDebug(`Processing type declaration: ${declaration}`)
const lines = declaration.split('\n')
const typeName = lines[0].split('type')[1].split('=')[0].trim()
const typeBody = lines.slice(1).join('\n').trim().replace(/;$/, '')
const result = `export declare type ${typeName} = ${typeBody}`
const firstLine = lines[0]
const typeName = firstLine.split('type')[1].split('=')[0].trim()
const typeBody = firstLine.split('=')[1]?.trim() || lines.slice(1).join('\n').trim().replace(/;$/, '')
const result = `export declare type ${typeName} = ${typeBody};`
logDebug(`Processed type declaration: ${result}`)
return result
}
Expand Down

0 comments on commit 03e59cb

Please sign in to comment.