Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbbreuer committed Oct 30, 2024
1 parent 8fd07e8 commit 0e5506d
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 10 deletions.
1 change: 1 addition & 0 deletions fixtures/input/variable.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
import process from 'node:process'
import type { DtsGenerationConfig } from '@stacksjs/dtsx'

Expand Down
5 changes: 1 addition & 4 deletions src/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { processImports, processSourceFile, processValue } from './process'
import { trackTypeUsage, trackValueUsage } from './track'
import { debugLog, normalizeType, splitObjectProperties } from './utils'

/* eslint-disable regexp/no-super-linear-backtracking */

/**
* Extracts types from a TypeScript file and generates corresponding .d.ts content
* @param filePath - Path to source TypeScript file
Expand Down Expand Up @@ -108,8 +106,7 @@ function extractBalancedSymbols(text: string, openSymbol: string, closeSymbol: s
export function extractFunctionSignature(declaration: string): FunctionSignature {
// Remove comments and clean up the declaration
const cleanDeclaration = removeLeadingComments(declaration).trim()

const functionPattern = /^\s*(export\s+)?(async\s+)?function\s*(\*)?\s*([^(<\s]+)/
const functionPattern = /^\s*(export\s+)?(async\s+)?function\s*(?:(\*)\s*)?([^(<\s]+)/
const functionMatch = cleanDeclaration.match(functionPattern)

if (!functionMatch) {
Expand Down
2 changes: 1 addition & 1 deletion src/is.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function isDeclarationStart(line: string): boolean {
|| line.startsWith('async function ')
|| line.startsWith('declare ')
|| line.startsWith('declare module')
|| /^export\s+(interface|type|const|function|async\s+function)/.test(line)
|| /^export\s+(?:interface|type|const|function|async\s+function)/.test(line)
|| line.startsWith('export async function')
)
}
Expand Down
1 change: 1 addition & 0 deletions src/process.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable regexp/no-super-linear-backtracking,regexp/optimal-quantifier-concatenation */
import type { ProcessingState, PropertyInfo } from './types'
import { cleanComments, removeLeadingComments } from './comments'
import { extractCleanObjectLiteral, extractFunctionSignature, extractObjectProperties } from './extract'
Expand Down
7 changes: 2 additions & 5 deletions src/track.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/**
* Regular expression patterns used throughout the module
* @remarks These patterns are optimized for performance and reliability
*/
/* eslint-disable no-cond-assign, regexp/no-super-linear-backtracking, regexp/no-misleading-capturing-group */

const REGEX = {
typePattern: /(?:typeof\s+)?([A-Z]\w*(?:<[^>]+>)?)|extends\s+([A-Z]\w*(?:<[^>]+>)?)/g,
} as const
Expand All @@ -11,7 +9,6 @@ const REGEX = {
*/
export function trackUsedTypes(content: string, usedTypes: Set<string>): void {
let match: any

while ((match = REGEX.typePattern.exec(content)) !== null) {
const type = match[1] || match[2]
if (type) {
Expand Down
1 change: 1 addition & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable regexp/no-super-linear-backtracking */
import type { DtsGenerationConfig, ProcessingState } from './types'
import { readdir } from 'node:fs/promises'
import { extname, join } from 'node:path'
Expand Down

0 comments on commit 0e5506d

Please sign in to comment.