From 594671c80f3b3a1f0189be8bd3808453ef971ac3 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 21 Oct 2024 21:54:58 +0200 Subject: [PATCH] chore: wip --- fixtures/output/example-0001.d.ts | 9 ++++++--- src/extract.ts | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/fixtures/output/example-0001.d.ts b/fixtures/output/example-0001.d.ts index 6e6c5e2..c7ecde3 100644 --- a/fixtures/output/example-0001.d.ts +++ b/fixtures/output/example-0001.d.ts @@ -1,5 +1,6 @@ import type { DtsGenerationOption, DtsGenerationConfig } from '@stacksjs/dtsx'; import type { BunPlugin } from 'bun'; +import { generate } from '@stacksjs/dtsx'; /** * Example of const declaration @@ -58,7 +59,7 @@ export declare function getProduct(id: number): Promise>; export declare interface AuthResponse { token: string; expiresIn: number; -} +}; export declare type AuthStatus = 'authenticated' | 'unauthenticated'; @@ -78,9 +79,11 @@ interface Options { export declare function loadConfig>(options: Options): Promise; -export declare const dtsConfig: DtsGenerationConfig; +declare const dtsConfig: DtsGenerationConfig; + +export { generate, dtsConfig }; -export { generate } from '@stacksjs/dtsx'; +export type { DtsGenerationOption }; export { config } from './config'; export * from './extract'; diff --git a/src/extract.ts b/src/extract.ts index 859f4b3..ee01a9f 100644 --- a/src/extract.ts +++ b/src/extract.ts @@ -189,7 +189,8 @@ function processFunctionDeclaration(declaration: string): string { const asyncKeyword = functionSignature.includes('async') ? 'async ' : '' const functionName = functionSignature.replace('export ', '').replace('async ', '').split('(')[0].trim() const params = functionSignature.split('(')[1].split(')')[0].trim() - const result = `export declare ${asyncKeyword}function ${functionName}(${params}): ${getReturnType(declaration)};` + const returnType = getReturnType(declaration) + const result = `export declare ${asyncKeyword}function ${functionName}(${params}): ${returnType};` logDebug(`Processed function declaration: ${result}`) return result }