Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbbreuer committed Oct 21, 2024
1 parent d079742 commit c71dccd
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,16 @@ function processDeclaration(declaration: string): string {

// Handle multi-line object literals
if (value.startsWith('{')) {
const lastBracketIndex = value.lastIndexOf('}')
if (lastBracketIndex !== -1) {
value = value.slice(0, lastBracketIndex + 1)
let bracketCount = 1
let i = 1
while (bracketCount > 0 && i < value.length) {
if (value[i] === '{')
bracketCount++
if (value[i] === '}')
bracketCount--
i++
}
value = value.slice(0, i)
}

const declaredType = name.includes(':') ? name.split(':')[1].trim() : null
Expand Down Expand Up @@ -137,9 +143,12 @@ function parseObjectLiteral(objectLiteral: string): string {
let currentPair = ''
let inQuotes = false
let bracketCount = 0
let escapeNext = false

for (const char of content) {
if (char === '"' || char === '\'') {
for (let i = 0; i < content.length; i++) {
const char = content[i]

if (!escapeNext && (char === '"' || char === '\'')) {
inQuotes = !inQuotes
}
else if (!inQuotes) {
Expand All @@ -156,6 +165,8 @@ function parseObjectLiteral(objectLiteral: string): string {
else {
currentPair += char
}

escapeNext = char === '\\' && !escapeNext
}

if (currentPair.trim()) {
Expand All @@ -181,7 +192,7 @@ function preserveValueType(value: string): string {
value = value.trim()
if (value.startsWith('\'') || value.startsWith('"')) {
// Handle string literals, including URLs
return value // Keep the original string as is
return value // Keep the original string as is, including quotes
}
else if (value === 'true' || value === 'false') {
return value // Keep true and false as literal types
Expand Down

0 comments on commit c71dccd

Please sign in to comment.