2
0

utils.ts 656 B

1234567891011121314151617181920212223242526272829
  1. import { parse, SFCScriptCompileOptions, compileScript } from '../src'
  2. import { parse as babelParse } from '@babel/parser'
  3. export const mockId = 'xxxxxxxx'
  4. export function compileSFCScript(
  5. src: string,
  6. options?: Partial<SFCScriptCompileOptions>
  7. ) {
  8. const { descriptor } = parse(src)
  9. return compileScript(descriptor, {
  10. ...options,
  11. id: mockId
  12. })
  13. }
  14. export function assertCode(code: string) {
  15. // parse the generated code to make sure it is valid
  16. try {
  17. babelParse(code, {
  18. sourceType: 'module',
  19. plugins: ['typescript']
  20. })
  21. } catch (e: any) {
  22. console.log(code)
  23. throw e
  24. }
  25. expect(code).toMatchSnapshot()
  26. }