utils.ts 562 B

1234567891011121314151617
  1. import { compile } from '../src'
  2. export function getCompiledString(src: string): string {
  3. // Wrap src template in a root div so that it doesn't get injected
  4. // fallthrough attr. This results in less noise in generated snapshots
  5. // but also means this util can only be used for non-root cases.
  6. const { code } = compile(`<div>${src}</div>`)
  7. const match = code.match(
  8. /_push\(`<div\${\s*_ssrRenderAttrs\(_attrs\)\s*}>([^]*)<\/div>`\)/,
  9. )
  10. if (!match) {
  11. throw new Error(`Unexpected compile result:\n${code}`)
  12. }
  13. return `\`${match[1]}\``
  14. }