export function parseJsonc(raw: string): unknown { const stripped = stripJsonComments(raw); return JSON.parse(stripped); } function stripJsonComments(text: string): string { let result = ""; let inString = false; let escape = false; let inLineComment = false; let inBlockComment = false; for (let i = 0; i < text.length; i++) { const ch = text[i]; const next = text[i + 1]; if (inString) { result += ch; if (escape) { escape = false; } else if (ch === "\\") { escape = true; } else if (ch === '"') { inString = false; } continue; } if (inLineComment) { if (ch === "\n") { inLineComment = false; result += ch; } continue; } if (inBlockComment) { if (ch === "*" && next === "/") { inBlockComment = false; i++; } continue; } if (ch === '"') { inString = true; result += ch; continue; } if (ch === "/" && next === "/") { inLineComment = true; i++; continue; } if (ch === "/" && next === "*") { inBlockComment = true; i++; continue; } result += ch; } return result; }