| 59 | |
| 60 | // fallow-ignore-next-line complexity |
| 61 | function parseDeclarations(body: string): Record<string, string> { |
| 62 | const decls: Record<string, string> = {}; |
| 63 | let depth = 0; |
| 64 | let quote: string | null = null; |
| 65 | let start = 0; |
| 66 | for (let i = 0; i <= body.length; i++) { |
| 67 | const ch = i < body.length ? body[i]! : ";"; // sentinel flush |
| 68 | if (quote) { |
| 69 | if (ch === "\\") { |
| 70 | i++; |
| 71 | continue; |
| 72 | } // skip escaped char |
| 73 | if (ch === quote) quote = null; |
| 74 | continue; |
| 75 | } |
| 76 | if (ch === '"' || ch === "'") { |
| 77 | quote = ch; |
| 78 | continue; |
| 79 | } |
| 80 | if (ch === "(") depth++; |
| 81 | else if (ch === ")") depth--; |
| 82 | else if (ch === ";" && depth === 0) { |
| 83 | const part = body.slice(start, i); |
| 84 | const colon = part.indexOf(":"); |
| 85 | if (colon !== -1) { |
| 86 | const prop = part.slice(0, colon).trim(); |
| 87 | const value = part.slice(colon + 1).trim(); |
| 88 | if (prop && value) decls[prop] = value; |
| 89 | } |
| 90 | start = i + 1; |
| 91 | } |
| 92 | } |
| 93 | return decls; |
| 94 | } |
| 95 | |
| 96 | function serializeDeclarations(decls: Record<string, string>): string { |
| 97 | const entries = Object.entries(decls); |