Skip to content

Commit e808e1a

Browse files
committed
chore: wip
1 parent 1e3996e commit e808e1a

File tree

6 files changed

+17
-11
lines changed

6 files changed

+17
-11
lines changed

src/processor.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,14 @@ export function processDeclarations(
110110
}
111111
}
112112

113-
// Check which imports are needed for interfaces and types (only exported ones)
113+
// Check which imports are needed for interfaces and types (including non-exported ones that are referenced by exported items)
114114
for (const iface of interfaces) {
115-
if (iface.isExported) {
115+
// Include interface if it's exported OR if it's referenced by exported functions
116+
const isReferencedByExports = functions.some(func =>
117+
func.isExported && func.text.includes(iface.name)
118+
)
119+
120+
if (iface.isExported || isReferencedByExports) {
116121
for (const imp of imports) {
117122
const importMatch = imp.text.match(/import\s+(?:type\s+)?\{?\s*([^}]+)\s*\}?\s+from/)
118123
if (importMatch) {
@@ -176,7 +181,7 @@ export function processDeclarations(
176181
}
177182
}
178183

179-
// Create filtered imports based on actually used items
184+
// Create filtered imports based on actually used items
180185
const processedImports: string[] = []
181186
for (const imp of imports) {
182187
const importMatch = imp.text.match(/import\s+(?:type\s+)?\{?\s*([^}]+)\s*\}?\s+from\s+['"]([^'"]+)['"]/)
@@ -189,11 +194,12 @@ export function processDeclarations(
189194

190195
if (usedItems.length > 0) {
191196
const source = importMatch[2]
192-
const hasTypeImports = usedItems.some(item => item.startsWith('type '))
193-
const hasValueImports = usedItems.some(item => !item.startsWith('type '))
197+
198+
// Check if original import was type-only
199+
const isOriginalTypeOnly = imp.text.includes('import type')
194200

195201
let importStatement = 'import '
196-
if (hasTypeImports && !hasValueImports) {
202+
if (isOriginalTypeOnly) {
197203
importStatement += 'type '
198204
}
199205
importStatement += `{ ${usedItems.join(', ')} } from '${source}';`

test/fixtures/output/example/0005.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ProcessingState } from './types';
1+
import type { ProcessingState } from './types';
22
export declare function extract(filePath: string): Promise<string>;
33
export declare function extractDtsTypes(sourceCode: string): string;
44
export declare function isFunctionType(type: string): boolean;

test/fixtures/output/example/0006.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { type Collection } from '@stacksjs/collections';
1+
import { type Collection } from '@stacksjs/collections';
22
export declare const quotes: Collection<string[]>;
33
export {
44
align,

test/fixtures/output/example/0007.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { CAOptions, CertificateOptions, GenerateCertReturn, TlsOption } from './types';
21
import { forge, tls } from 'node-forge';
32
import { os } from 'node:os';
3+
import type { CAOptions, CertificateOptions, GenerateCertReturn, TlsOption } from './types';
44
export declare function generateRandomSerial(verbose?: boolean): string;
55
export declare function calculateValidityDates(options: {
66
validityDays?: number

test/fixtures/output/example/0008.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { CertDetails } from './types';
21
import { os } from 'node:os';
32
import { pki } from 'node-forge';
3+
import type { CertDetails } from './types';
44
export declare function isCertValidForDomain(certPemOrPath: string, domain: string): boolean;
55
export declare function readCertFromFile(certPath: string): string;
66
export declare function parseCertDetails(certPemOrPath: string): CertDetails;

test/fixtures/output/example/0009.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Config } from './types';
1+
import type { Config } from './types';
22
export declare function loadConfig<T>({
33
name,
44
cwd,

0 commit comments

Comments
 (0)