@@ -4,13 +4,10 @@ import {
44 delegateEvents ,
55} from '../src'
66import { defineAsyncComponent , nextTick , reactive , ref } from '@vue/runtime-dom'
7- import { compileScript , parse } from '@vue/compiler-sfc'
8- import * as runtimeVapor from '../src'
9- import * as runtimeDom from '@vue/runtime-dom'
10- import * as VueServerRenderer from '@vue/server-renderer'
117import { isString } from '@vue/shared'
128import type { VaporComponentInstance } from '../src/component'
139import type { TeleportFragment } from '../src/components/Teleport'
10+ import { VueServerRenderer , compile , runtimeDom , runtimeVapor } from './_utils'
1411
1512const formatHtml = ( raw : string ) => {
1613 return raw
@@ -19,48 +16,6 @@ const formatHtml = (raw: string) => {
1916 . replace ( / \n { 2 , } / g, '\n' )
2017}
2118
22- const Vue = { ...runtimeDom , ...runtimeVapor }
23-
24- function compile (
25- sfc : string ,
26- data : runtimeDom . Ref < any > ,
27- components : Record < string , any > = { } ,
28- { vapor = true , ssr = false } = { } ,
29- ) {
30- if ( ! sfc . includes ( `<script` ) ) {
31- sfc =
32- `<script vapor>const data = _data; const components = _components;</script>` +
33- sfc
34- }
35- const descriptor = parse ( sfc ) . descriptor
36-
37- const script = compileScript ( descriptor , {
38- id : 'x' ,
39- isProd : true ,
40- inlineTemplate : true ,
41- genDefaultAs : '__sfc__' ,
42- vapor,
43- templateOptions : {
44- ssr,
45- } ,
46- } )
47-
48- const code =
49- script . content
50- . replace ( / \b i m p o r t { / g, 'const {' )
51- . replace ( / a s _ / g, ': _' )
52- . replace ( / } f r o m [ ' " ] v u e [ ' " ] / g, `} = Vue` )
53- . replace ( / } f r o m " v u e \/ s e r v e r - r e n d e r e r " / g, '} = VueServerRenderer' ) +
54- '\nreturn __sfc__'
55-
56- return new Function ( 'Vue' , 'VueServerRenderer' , '_data' , '_components' , code ) (
57- Vue ,
58- VueServerRenderer ,
59- data ,
60- components ,
61- )
62- }
63-
6419async function testWithVaporApp (
6520 code : string ,
6621 components ?: Record < string , string | { code : string ; vapor : boolean } > ,
0 commit comments