Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbbreuer committed Oct 22, 2024
1 parent 1a8a76e commit 73d453e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
6 changes: 1 addition & 5 deletions fixtures/output/example-0001.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { BunPlugin } from 'bun'
import type { DtsGenerationConfig, DtsGenerationOption } from '@stacksjs/dtsx'
import type { BunPlugin } from 'bun';
/**
* Example of const declaration
Expand Down Expand Up @@ -103,6 +101,4 @@ export * from './extract'
export * from './generate'
export * from './types'
export * from './utils'

export default
export default dts;
export default dts;
22 changes: 17 additions & 5 deletions src/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ export function processDeclarationLine(line: string, state: ProcessingState): vo
}
}

function formatOutput(state: ProcessingState): string {
export function formatOutput(state: ProcessingState): string {
const uniqueImports = processImports(state.imports, state.usedTypes)
const dynamicImports = Array.from(state.usedTypes)
.map((type) => {
Expand All @@ -816,16 +816,28 @@ function formatOutput(state: ProcessingState): string {
line.startsWith('*') ? ` ${line}` : line,
)

const result = [
let result = [
...allImports,
'',
'', // Extra newline after imports
...declarations,
].filter(Boolean).join('\n')

return state.defaultExport
? `${result}\n\nexport default ${state.defaultExport.trim()};\n`
: `${result}\n`
// Clean up default export - extract just the identifier
if (state.defaultExport) {
const exportIdentifier = state.defaultExport
.replace(/^export\s+default\s+/, '') // Remove leading export default
.replace(/export\s+default\s+/, '') // Remove any additional export default
.replace(/;+$/, '') // Remove trailing semicolons
.trim()

result += `\nexport default ${exportIdentifier};\n`
}
else {
result += '\n'
}

return result
}

/**
Expand Down

0 comments on commit 73d453e

Please sign in to comment.