Skip to content

Commit

Permalink
chore: couple minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbbreuer committed Nov 9, 2024
1 parent dfdf3cc commit cf0928f
Show file tree
Hide file tree
Showing 4 changed files with 313 additions and 62 deletions.
176 changes: 176 additions & 0 deletions fixtures/input/example/0004.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
/**
* DtsGenerationConfig
*
* This is the configuration object for the DTS generation process.
*/
export interface DtsGenerationConfig {
cwd: string
root: string
entrypoints: string[]
outdir: string
keepComments: boolean
clean: boolean
tsconfigPath: string
verbose: boolean
}

/**
* DtsGenerationOption
*
* This is the configuration object for the DTS generation process.
*/
export type DtsGenerationOption = Partial<DtsGenerationConfig>

/**
* DtsGenerationOptions
*
* This is the configuration object for the DTS generation process.
*/
export type DtsGenerationOptions = DtsGenerationOption | DtsGenerationOption[]

/**
* Regular expression patterns used throughout the module
*/
export interface RegexPatterns {
/** Import type declarations */
readonly typeImport: RegExp
/** Regular import declarations */
readonly regularImport: RegExp
/** Opening brackets and braces */
readonly bracketOpen: RegExp
/** Closing brackets and braces */
readonly bracketClose: RegExp
/** Function return statements */
readonly functionReturn: RegExp
/** Type annotation patterns */
readonly typeAnnotation: RegExp
/** Async function declarations */
readonly asyncFunction: RegExp
/** Generic type parameters */
readonly genericParams: RegExp
/** Function parameter block */
readonly functionParams: RegExp
/** Return type declaration */
readonly functionReturnType: RegExp
/** Destructured parameters */
readonly destructuredParams: RegExp
/** Type pattern matching */
readonly typePattern: RegExp
/** Value reference pattern */
readonly valueReference: RegExp
/** Type reference pattern */
readonly typeReference: RegExp
/** Function name extraction */
readonly functionName: RegExp
/** Export statement cleanup */
readonly exportCleanup: RegExp
/** Default export */
readonly defaultExport: RegExp
/** Named export */
readonly complexType: RegExp
/** Union and intersection types */
readonly unionIntersection: RegExp
/** Conditional types */
readonly mappedType: RegExp
/** Conditional types */
readonly conditionalType: RegExp
/** Generic constraints */
readonly genericConstraints: RegExp
/** Function overload */
readonly functionOverload: RegExp
/** Module declaration pattern */
readonly moduleDeclaration: RegExp
/** Module augmentation pattern */
readonly moduleAugmentation: RegExp
}

export interface ImportTrackingState {
typeImports: Map<string, Set<string>> // module -> Set of type names
valueImports: Map<string, Set<string>> // module -> Set of value names
usedTypes: Set<string> // All used type names
usedValues: Set<string> // All used value names
exportedTypes: Set<string> // Types that are exported
exportedValues: Set<string> // Values that are exported
valueAliases: Map<string, string> // alias -> original name mapping
importSources: Map<string, string> // name -> module mapping
typeExportSources: Map<string, string> // type name -> source module for type exports
defaultExportValue?: string // The value being default exported
}

export interface ProcessingState {
dtsLines: string[]
imports: string[]
usedTypes: Set<string>
typeSources: Map<string, string>
defaultExport: string | null
exportAllStatements: string[]
currentDeclaration: string
lastCommentBlock: string
bracketCount: number
isMultiLineDeclaration: boolean
moduleImports: Map<string, ImportInfo>
availableTypes: Map<string, string>
availableValues: Map<string, string>
currentIndentation: string
declarationBuffer: {
type: 'interface' | 'type' | 'const' | 'function' | 'import' | 'export'
indent: string
lines: string[]
comments: string[]
} | null
importTracking: ImportTrackingState
defaultExports: Set<string>
currentScope: 'top' | 'function'
}

export interface MethodSignature {
name: string
async: boolean
generics: string
params: string
returnType: string
}

/**
* Represents property type information with support for nested structures
*/
export interface PropertyInfo {
/** Property identifier */
key: string
/** Original source value */
value: string
/** Inferred TypeScript type */
type: string
/** Nested property definitions */
nested?: PropertyInfo[]
method?: MethodSignature
}

/**
* Import statement metadata and tracking
*/
export interface ImportInfo {
/** Import kind: type, value, or mixed */
kind: 'type' | 'value' | 'mixed'
/** Set of used type imports */
usedTypes: Set<string>
/** Set of used value imports */
usedValues: Set<string>
/** Source module path */
source: string
}

/**
* Function signature components
*/
export interface FunctionSignature {
name: string
params: string
returnType: string
generics: string
}

export interface ProcessedMethod {
name: string
signature: string
}
106 changes: 106 additions & 0 deletions fixtures/output/0004.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
export declare interface DtsGenerationConfig {
cwd: string
root: string
entrypoints: string[]
outdir: string
keepComments: boolean
clean: boolean
tsconfigPath: string
verbose: boolean
}
export declare type DtsGenerationOption = Partial<DtsGenerationConfig>
export declare type DtsGenerationOptions = DtsGenerationOption | DtsGenerationOption[]
export declare interface RegexPatterns {
readonly typeImport: RegExp
readonly regularImport: RegExp
readonly bracketOpen: RegExp
readonly bracketClose: RegExp
readonly functionReturn: RegExp
readonly typeAnnotation: RegExp
readonly asyncFunction: RegExp
readonly genericParams: RegExp
readonly functionParams: RegExp
readonly functionReturnType: RegExp
readonly destructuredParams: RegExp
readonly typePattern: RegExp
readonly valueReference: RegExp
readonly typeReference: RegExp
readonly functionName: RegExp
readonly exportCleanup: RegExp
readonly defaultExport: RegExp
readonly complexType: RegExp
readonly unionIntersection: RegExp
readonly mappedType: RegExp
readonly conditionalType: RegExp
readonly genericConstraints: RegExp
readonly functionOverload: RegExp
readonly moduleDeclaration: RegExp
readonly moduleAugmentation: RegExp
}
export declare interface ImportTrackingState {
typeImports: Map<string, Set<string>>
valueImports: Map<string, Set<string>>
usedTypes: Set<string>
usedValues: Set<string>
exportedTypes: Set<string>
exportedValues: Set<string>
valueAliases: Map<string, string>
importSources: Map<string, string>
typeExportSources: Map<string, string>
defaultExportValue?: string
}
export declare interface ProcessingState {
dtsLines: string[]
imports: string[]
usedTypes: Set<string>
typeSources: Map<string, string>
defaultExport: string | null
exportAllStatements: string[]
currentDeclaration: string
lastCommentBlock: string
bracketCount: number
isMultiLineDeclaration: boolean
moduleImports: Map<string, ImportInfo>
availableTypes: Map<string, string>
availableValues: Map<string, string>
currentIndentation: string
declarationBuffer: {
type: 'interface' | 'type' | 'const' | 'function' | 'import' | 'export'
indent: string
lines: string[]
comments: string[]
} | null
importTracking: ImportTrackingState
defaultExports: Set<string>
currentScope: 'top' | 'function'
}
export declare interface MethodSignature {
name: string
async: boolean
generics: string
params: string
returnType: string
}
export declare interface PropertyInfo {
key: string
value: string
type: string
nested?: PropertyInfo[]
method?: MethodSignature
}
export declare interface ImportInfo {
kind: 'type' | 'value' | 'mixed'
usedTypes: Set<string>
usedValues: Set<string>
source: string
}
export declare interface FunctionSignature {
name: string
params: string
returnType: string
generics: string
}
export declare interface ProcessedMethod {
name: string
signature: string
}
3 changes: 3 additions & 0 deletions fixtures/output/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export type RecursiveObject = {
metadata: Record<string, unknown>
}
export declare type UserId = string & { readonly __brand: unique symbol }
export type ProductId = number & {
readonly __brand: unique symbol
}
export declare type DeepPartial<T> = T extends object ? {
[P in keyof T]?: DeepPartial<T[P]>
} : T
Expand Down
Loading

0 comments on commit cf0928f

Please sign in to comment.