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KAAK,CAAA,EAAG,UAAU,CAAA;AACxG,EAAM,MAAA,YAAA,GAAe,OAAQ,CAAA,SAAA,CAAU,UAAU,CAAA;AAEjD,EAAO,OAAA,CAAC,UAAY,EAAA,eAAA,CAAgB,YAAY,CAAC,EAAE,MAAO,CAAA,OAAO,CAAE,CAAA,IAAA,CAAK,IAAI,CAAA;AAC9E;ACpDA,IAAM,aAAyB,GAAA;AAAA,EAC7B,QAAU,EAAA,CAAA;AAAA,EACV,UAAY,EAAA,GAAA;AAAA,EACZ,MAAQ,EAAA,YAAA;AAAA,EACR,WAAa,EAAA,IAAA;AAAA,EACb,IAAM,EAAA,KAAA;AAAA,EACN,eAAiB,EAAA,KAAA;AAAA,EACjB,SAAW,EAAA,MAAA;AAAA,EACX,OAAA,EAAS,CAACC,iCAAgB;AAC5B,CAAA;AAKA,eAAsB,OAAO,MAAgB,EAAA;AAE3C,EAAA,IAAI,CAAC,MAAQ,EAAA;AACX,IAAO,OAAA,EAAA;AAAA;AAGT,EAAO,OAAAC,eAAA,CAAe,QAAQ,aAAa,CAAA;AAC7C","file":"index.cjs","sourcesContent":["import ts from 'typescript'\n\nimport type { PrinterOptions } from 'typescript'\n\nconst { factory } = ts\n\nexport type PrintOptions = {\n  source?: string\n  baseName?: string\n  scriptKind?: ts.ScriptKind\n} & PrinterOptions\n\n/**\n * Escaped new lines in code with block comments so they can be restored by {@link restoreNewLines}\n * @param {string} code The code to escape new lines in\n * @returns The same code but with new lines escaped using block comments\n */\nconst escapeNewLines = (code: string) => code.replace(/\\n\\n/g, '\\n/* :newline: */')\n\n/**\n * Reverses {@link escapeNewLines} and restores new lines\n * @param {string} code The code with escaped new lines\n * @returns The same code with new lines restored\n */\nconst restoreNewLines = (code: string) => code.replace(/\\/\\* :newline: \\*\\//g, '\\n')\n\n/**\n * Convert AST TypeScript nodes to a string based on the TypeScript printer.\n */\nexport function print(\n  elements: Array<ts.Node>,\n  { source = '', baseName = 'print.ts', removeComments, noEmitHelpers, newLine = ts.NewLineKind.LineFeed, scriptKind = ts.ScriptKind.TS }: PrintOptions = {},\n): string {\n  const sourceFile = ts.createSourceFile(baseName, escapeNewLines(source), ts.ScriptTarget.ES2022, false, scriptKind)\n  const printer = ts.createPrinter({\n    omitTrailingSemicolon: true,\n    newLine,\n    removeComments,\n    noEmitHelpers,\n  })\n\n  let nodes: Array<ts.Node> = []\n\n  if (!elements) {\n    return ''\n  }\n\n  if (Array.isArray(elements)) {\n    nodes = elements.filter(Boolean)\n  } else {\n    nodes = [elements].filter(Boolean)\n  }\n\n  const outputFile = printer.printList(ts.ListFormat.MultiLine, factory.createNodeArray(nodes), sourceFile)\n  const outputSource = printer.printFile(sourceFile)\n\n  return [outputFile, restoreNewLines(outputSource)].filter(Boolean).join('\\n')\n}\n","import { format as prettierFormat } from 'prettier'\nimport pluginTypescript from 'prettier/plugins/typescript'\n\nimport type { Options } from 'prettier'\n\nconst formatOptions: Options = {\n  tabWidth: 2,\n  printWidth: 160,\n  parser: 'typescript',\n  singleQuote: true,\n  semi: false,\n  bracketSameLine: false,\n  endOfLine: 'auto',\n  plugins: [pluginTypescript],\n}\n\n/**\n * Format the generated code based on Prettier\n */\nexport async function format(source: string) {\n  // do some basic linting with the ts compiler\n  if (!source) {\n    return ''\n  }\n\n  return prettierFormat(source, formatOptions)\n}\n"]}