Skip to content

Commit 414908d

Browse files
committed
chore: wip
1 parent 9c11ad7 commit 414908d

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/extract.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export async function extractTypeFromSource(filePath: string): Promise<string> {
8686
declarations += `${pendingComment}\n`
8787
pendingComment = ''
8888
}
89-
declarations += `export declare const ${constName}: {\n${formattedValue}\n}\n\n`
89+
declarations += `export declare const ${constName}: {\n${formattedValue}\n}\n`
9090
}
9191
else {
9292
// Handle constants initialized with function calls
@@ -97,15 +97,15 @@ export async function extractTypeFromSource(filePath: string): Promise<string> {
9797
declarations += `${pendingComment}\n`
9898
pendingComment = ''
9999
}
100-
declarations += `export declare const ${constName}: ${constType.trim()}\n\n`
100+
declarations += `export declare const ${constName}: ${constType.trim()}\n`
101101
}
102102
else {
103103
// Fallback to the original declaration if parsing fails
104104
if (pendingComment) {
105105
declarations += `${pendingComment}\n`
106106
pendingComment = ''
107107
}
108-
declarations += `export declare ${declaration.replace(/export\s+/, '').trim()}\n\n`
108+
declarations += `export declare ${declaration.replace(/export\s+/, '').trim()}\n`
109109
}
110110
}
111111
}
@@ -114,7 +114,7 @@ export async function extractTypeFromSource(filePath: string): Promise<string> {
114114
declarations += `${pendingComment}\n`
115115
pendingComment = ''
116116
}
117-
declarations += `${declaration.trim()}\n\n`
117+
declarations += `${declaration.trim()}\n`
118118
}
119119
else if (declType === 'function' || declType === 'async function') {
120120
if (pendingComment) {
@@ -126,7 +126,7 @@ export async function extractTypeFromSource(filePath: string): Promise<string> {
126126

127127
if (funcSignatureMatch) {
128128
const [, isAsync, funcName, params, returnType] = funcSignatureMatch
129-
declarations += `export declare ${isAsync || ''}function ${funcName}(${params.trim()}): ${returnType.trim()}\n\n`
129+
declarations += `export declare ${isAsync || ''}function ${funcName}(${params.trim()}): ${returnType.trim()}\n`
130130
}
131131
else {
132132
// If we can't match the full signature, let's try to extract what we can
@@ -140,12 +140,12 @@ export async function extractTypeFromSource(filePath: string): Promise<string> {
140140
const returnTypeMatch = declaration.match(returnTypeRegex)
141141
const returnType = returnTypeMatch ? returnTypeMatch[1].trim() : 'any'
142142

143-
declarations += `export declare ${isAsync || ''}function ${funcName}(${params.trim()}): ${returnType}\n\n`
143+
declarations += `export declare ${isAsync || ''}function ${funcName}(${params.trim()}): ${returnType}\n`
144144
}
145145
else {
146146
// If all else fails, just add 'declare' to the original export
147147
const simplifiedDeclaration = declaration.replace(/export\s+/, '').split('{')[0].trim()
148-
declarations += `export declare ${simplifiedDeclaration}\n\n`
148+
declarations += `export declare ${simplifiedDeclaration}\n`
149149
}
150150
}
151151
}
@@ -172,14 +172,14 @@ export async function extractTypeFromSource(filePath: string): Promise<string> {
172172
const typeExportMatches = Array.from(fileContent.matchAll(typeExportRegex))
173173
for (const [, typeList] of typeExportMatches) {
174174
const types = typeList.split(',').map(t => t.trim())
175-
exports += `\n\nexport type { ${types.join(', ')} }`
175+
exports += `\nexport type { ${types.join(', ')} }`
176176
}
177177

178178
// Handle default export
179179
const defaultExportRegex = /export\s+default\s+(\w+)/
180180
const defaultExportMatch = fileContent.match(defaultExportRegex)
181181
if (defaultExportMatch) {
182-
exports += `\n\nexport default ${defaultExportMatch[1]}`
182+
exports += `\nexport default ${defaultExportMatch[1]}`
183183
}
184184

185185
const output = [imports, declarations.trim(), exports.trim()].filter(Boolean).join('\n').trim()

0 commit comments

Comments
 (0)