Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbbreuer committed Nov 1, 2024
1 parent 75afa55 commit 1e6a590
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
2 changes: 1 addition & 1 deletion fixtures/output/variable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export declare const someObject: {
Array<
{
key2: 'value2'
} |
} |
'test' |
1000
> |
Expand Down
14 changes: 3 additions & 11 deletions src/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,17 +510,16 @@ function indentMultilineType(type: string, baseIndent: string, isLast: boolean):
return ''

// Track Array type specifically
// const isArrayStart = trimmed.startsWith('Array<')
const openBrackets = (trimmed.match(/[{<[]/g) || [])
const closeBrackets = (trimmed.match(/[}\]>]/g) || [])
const openBrackets = trimmed.match(/[{<[]/g) || []
const closeBrackets = trimmed.match(/[}\]>]/g) || []

let currentIndent = baseIndent
if (i > 0) {
const stackDepth = bracketStack.reduce((depth, info) => depth + info.depth, 0)
currentIndent = baseIndent + ' '.repeat(stackDepth)

// Dedent closing tokens
if ((trimmed === '}' || trimmed === '>' || trimmed.startsWith('> |')) && bracketStack.length > 0) {
if ((trimmed.startsWith('}') || trimmed.startsWith('>') || trimmed.startsWith('> |')) && bracketStack.length > 0) {
currentIndent = baseIndent + ' '.repeat(Math.max(0, stackDepth - 1))
}
}
Expand Down Expand Up @@ -557,7 +556,6 @@ function indentMultilineType(type: string, baseIndent: string, isLast: boolean):
// Handle special cases for objects in arrays
if (trimmed === '}') {
const lastArray = [...bracketStack].reverse().find(info => info.isArray)
// Don't add union if this is the only element in the array
if (lastArray?.isSingleElement) {
needsUnion = false
}
Expand Down Expand Up @@ -904,12 +902,6 @@ export function isDeclarationComplete(content: string | string[]): boolean {
return /;\s*$/.test(trimmedContent) || /\}\s*$/.test(trimmedContent)
}

function isMethodDeclaration(text: string): boolean {
debugLog(undefined, 'method-check', `Checking if method declaration: ${text}`)
// Simple check - either has parentheses in the key or starts with async
return text.includes('(') || text.startsWith('async')
}

function needsMultilineFormat(types: string[]): boolean {
return types.some(type =>
type.includes('\n')
Expand Down

0 comments on commit 1e6a590

Please sign in to comment.