{"version":3,"file":"twoslash.cjs.production.min.js","sources":["../src/utils.ts","../src/index.ts","../src/validation.ts"],"sourcesContent":["import { TwoslashError } from \"./\"\n\nexport function escapeHtml(text: string) {\n return text.replace(/ = {\n js: \"js\",\n javascript: \"js\",\n ts: \"ts\",\n typescript: \"ts\",\n tsx: \"tsx\",\n jsx: \"jsx\",\n json: \"json\",\n jsn: \"json\",\n }\n\n if (map[types]) return map[types]\n\n throw new TwoslashError(\n `Unknown TypeScript extension given to Twoslash`,\n `Received ${types} but Twoslash only accepts: ${Object.keys(map)} `,\n ``\n )\n}\n\nexport function getIdentifierTextSpans(ts: typeof import(\"typescript\"), sourceFile: import(\"typescript\").SourceFile) {\n const textSpans: { span: import(\"typescript\").TextSpan; text: string }[] = []\n checkChildren(sourceFile)\n return textSpans\n\n function checkChildren(node: import(\"typescript\").Node) {\n ts.forEachChild(node, child => {\n if (ts.isIdentifier(child)) {\n const start = child.getStart(sourceFile, false)\n textSpans.push({ span: ts.createTextSpan(start, child.end - start), text: child.getText(sourceFile) })\n }\n checkChildren(child)\n })\n }\n}\n\nexport function stringAroundIndex(string: string, index: number) {\n const arr = [\n string[index - 3],\n string[index - 2],\n string[index - 1],\n \">\",\n string[index],\n \"<\",\n string[index + 1],\n string[index + 2],\n string[index + 3],\n ]\n return arr.filter(Boolean).join(\"\")\n}\n\n/** Came from https://ourcodeworld.com/articles/read/223/how-to-retrieve-the-closest-word-in-a-string-with-a-given-index-in-javascript */\nexport function getClosestWord(str: string, pos: number) {\n // Make copies\n str = String(str)\n pos = Number(pos) >>> 0\n\n // Search for the word's beginning and end.\n var left = str.slice(0, pos + 1).search(/\\S+$/),\n right = str.slice(pos).search(/\\s/)\n\n // The last word in the string is a special case.\n if (right < 0) {\n return {\n word: str.slice(left),\n startPos: left,\n }\n }\n // Return the word, using the located bounds to extract it from the string.\n return {\n word: str.slice(left, right + pos),\n startPos: left,\n }\n}\n","let hasLocalStorage = false\ntry {\n hasLocalStorage = typeof localStorage !== `undefined`\n} catch (error) {}\nconst hasProcess = typeof process !== `undefined`\nconst shouldDebug = (hasLocalStorage && localStorage.getItem(\"DEBUG\")) || (hasProcess && process.env.DEBUG)\n\ntype LZ = typeof import(\"lz-string\")\ntype TS = typeof import(\"typescript\")\ntype CompilerOptions = import(\"typescript\").CompilerOptions\ntype CustomTransformers = import(\"typescript\").CustomTransformers\n\nimport { parsePrimitive, cleanMarkdownEscaped, typesToExtension, getIdentifierTextSpans, getClosestWord } from \"./utils\"\nimport { validateInput, validateCodeForErrors } from \"./validation\"\n\nimport { createSystem, createVirtualTypeScriptEnvironment, createFSBackedSystem } from \"@typescript/vfs\"\n\nconst log = shouldDebug ? console.log : (_message?: any, ..._optionalParams: any[]) => \"\"\n\n// Hacking in some internal stuff\ndeclare module \"typescript\" {\n type Option = {\n name: string\n type: \"list\" | \"boolean\" | \"number\" | \"string\" | import(\"typescript\").Map\n element?: Option\n }\n\n const optionDeclarations: Array