@@ -3,15 +3,14 @@ import { transformWithEsbuild } from '../../plugins/esbuild'
3
3
import { traverseHtml } from '../../plugins/html'
4
4
import { ssrTransform } from '../ssrTransform'
5
5
6
+ const ssrTransformSimple = async ( code : string , url = '' ) =>
7
+ ssrTransform ( code , null , url , code )
8
+ const ssrTransformSimpleCode = async ( code : string , url ?: string ) =>
9
+ ( await ssrTransformSimple ( code , url ) ) ?. code
10
+
6
11
test ( 'default import' , async ( ) => {
7
12
expect (
8
- (
9
- await ssrTransform (
10
- `import foo from 'vue';console.log(foo.bar)` ,
11
- null ,
12
- null
13
- )
14
- ) . code
13
+ await ssrTransformSimpleCode ( `import foo from 'vue';console.log(foo.bar)` )
15
14
) . toMatchInlineSnapshot ( `
16
15
"const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\");
17
16
console.log(__vite_ssr_import_0__.default.bar)"
@@ -20,13 +19,9 @@ test('default import', async () => {
20
19
21
20
test ( 'named import' , async ( ) => {
22
21
expect (
23
- (
24
- await ssrTransform (
25
- `import { ref } from 'vue';function foo() { return ref(0) }` ,
26
- null ,
27
- null
28
- )
29
- ) . code
22
+ await ssrTransformSimpleCode (
23
+ `import { ref } from 'vue';function foo() { return ref(0) }`
24
+ )
30
25
) . toMatchInlineSnapshot ( `
31
26
"const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\");
32
27
function foo() { return __vite_ssr_import_0__.ref(0) }"
@@ -35,48 +30,43 @@ test('named import', async () => {
35
30
36
31
test ( 'namespace import' , async ( ) => {
37
32
expect (
38
- (
39
- await ssrTransform (
40
- `import * as vue from 'vue';function foo() { return vue.ref(0) }` ,
41
- null ,
42
- null
43
- )
44
- ) . code
33
+ await ssrTransformSimpleCode (
34
+ `import * as vue from 'vue';function foo() { return vue.ref(0) }`
35
+ )
45
36
) . toMatchInlineSnapshot ( `
46
37
"const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\");
47
38
function foo() { return __vite_ssr_import_0__.ref(0) }"
48
39
` )
49
40
} )
50
41
51
42
test ( 'export function declaration' , async ( ) => {
52
- expect ( ( await ssrTransform ( `export function foo() {}` , null , null ) ) . code )
43
+ expect ( await ssrTransformSimpleCode ( `export function foo() {}` ) )
53
44
. toMatchInlineSnapshot ( `
54
45
"function foo() {}
55
46
Object.defineProperty(__vite_ssr_exports__, \\"foo\\", { enumerable: true, configurable: true, get(){ return foo }});"
56
47
` )
57
48
} )
58
49
59
50
test ( 'export class declaration' , async ( ) => {
60
- expect ( ( await ssrTransform ( `export class foo {}` , null , null ) ) . code )
51
+ expect ( await ssrTransformSimpleCode ( `export class foo {}` ) )
61
52
. toMatchInlineSnapshot ( `
62
53
"class foo {}
63
54
Object.defineProperty(__vite_ssr_exports__, \\"foo\\", { enumerable: true, configurable: true, get(){ return foo }});"
64
55
` )
65
56
} )
66
57
67
58
test ( 'export var declaration' , async ( ) => {
68
- expect ( ( await ssrTransform ( `export const a = 1, b = 2` , null , null ) ) . code )
59
+ expect ( await ssrTransformSimpleCode ( `export const a = 1, b = 2` ) )
69
60
. toMatchInlineSnapshot ( `
70
- "const a = 1, b = 2
71
- Object.defineProperty(__vite_ssr_exports__, \\"a\\", { enumerable: true, configurable: true, get(){ return a }});
72
- Object.defineProperty(__vite_ssr_exports__, \\"b\\", { enumerable: true, configurable: true, get(){ return b }});"
73
- ` )
61
+ "const a = 1, b = 2
62
+ Object.defineProperty(__vite_ssr_exports__, \\"a\\", { enumerable: true, configurable: true, get(){ return a }});
63
+ Object.defineProperty(__vite_ssr_exports__, \\"b\\", { enumerable: true, configurable: true, get(){ return b }});"
64
+ ` )
74
65
} )
75
66
76
67
test ( 'export named' , async ( ) => {
77
68
expect (
78
- ( await ssrTransform ( `const a = 1, b = 2; export { a, b as c }` , null , null ) )
79
- . code
69
+ await ssrTransformSimpleCode ( `const a = 1, b = 2; export { a, b as c }` )
80
70
) . toMatchInlineSnapshot ( `
81
71
"const a = 1, b = 2;
82
72
Object.defineProperty(__vite_ssr_exports__, \\"a\\", { enumerable: true, configurable: true, get(){ return a }});
@@ -86,8 +76,7 @@ test('export named', async () => {
86
76
87
77
test ( 'export named from' , async ( ) => {
88
78
expect (
89
- ( await ssrTransform ( `export { ref, computed as c } from 'vue'` , null , null ) )
90
- . code
79
+ await ssrTransformSimpleCode ( `export { ref, computed as c } from 'vue'` )
91
80
) . toMatchInlineSnapshot ( `
92
81
"const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\");
93
82
@@ -98,13 +87,9 @@ test('export named from', async () => {
98
87
99
88
test ( 'named exports of imported binding' , async ( ) => {
100
89
expect (
101
- (
102
- await ssrTransform (
103
- `import {createApp} from 'vue';export {createApp}` ,
104
- null ,
105
- null
106
- )
107
- ) . code
90
+ await ssrTransformSimpleCode (
91
+ `import {createApp} from 'vue';export {createApp}`
92
+ )
108
93
) . toMatchInlineSnapshot ( `
109
94
"const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\");
110
95
@@ -114,13 +99,9 @@ test('named exports of imported binding', async () => {
114
99
115
100
test ( 'export * from' , async ( ) => {
116
101
expect (
117
- (
118
- await ssrTransform (
119
- `export * from 'vue'\n` + `export * from 'react'` ,
120
- null ,
121
- null
122
- )
123
- ) . code
102
+ await ssrTransformSimpleCode (
103
+ `export * from 'vue'\n` + `export * from 'react'`
104
+ )
124
105
) . toMatchInlineSnapshot ( `
125
106
"const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\");
126
107
__vite_ssr_exportAll__(__vite_ssr_import_0__);
@@ -130,7 +111,7 @@ test('export * from', async () => {
130
111
} )
131
112
132
113
test ( 'export * as from' , async ( ) => {
133
- expect ( ( await ssrTransform ( `export * as foo from 'vue'` , null , null ) ) . code )
114
+ expect ( await ssrTransformSimpleCode ( `export * as foo from 'vue'` ) )
134
115
. toMatchInlineSnapshot ( `
135
116
"const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\");
136
117
@@ -140,148 +121,126 @@ test('export * as from', async () => {
140
121
141
122
test ( 'export default' , async ( ) => {
142
123
expect (
143
- ( await ssrTransform ( `export default {}` , null , null ) ) . code
124
+ await ssrTransformSimpleCode ( `export default {}` )
144
125
) . toMatchInlineSnapshot ( `"__vite_ssr_exports__.default = {}"` )
145
126
} )
146
127
147
128
test ( 'import.meta' , async ( ) => {
148
129
expect (
149
- ( await ssrTransform ( `console.log(import.meta.url)` , null , null ) ) . code
130
+ await ssrTransformSimpleCode ( `console.log(import.meta.url)` )
150
131
) . toMatchInlineSnapshot ( `"console.log(__vite_ssr_import_meta__.url)"` )
151
132
} )
152
133
153
134
test ( 'dynamic import' , async ( ) => {
154
- const result = await ssrTransform (
155
- `export const i = () => import('./foo')` ,
156
- null ,
157
- null
135
+ const result = await ssrTransformSimple (
136
+ `export const i = () => import('./foo')`
158
137
)
159
- expect ( result . code ) . toMatchInlineSnapshot ( `
138
+ expect ( result ? .code ) . toMatchInlineSnapshot ( `
160
139
"const i = () => __vite_ssr_dynamic_import__('./foo')
161
140
Object.defineProperty(__vite_ssr_exports__, \\"i\\", { enumerable: true, configurable: true, get(){ return i }});"
162
141
` )
163
- expect ( result . deps ) . toEqual ( [ ] )
164
- expect ( result . dynamicDeps ) . toEqual ( [ './foo' ] )
142
+ expect ( result ? .deps ) . toEqual ( [ ] )
143
+ expect ( result ? .dynamicDeps ) . toEqual ( [ './foo' ] )
165
144
} )
166
145
167
146
test ( 'do not rewrite method definition' , async ( ) => {
168
- const result = await ssrTransform (
169
- `import { fn } from 'vue';class A { fn() { fn() } }` ,
170
- null ,
171
- null
147
+ const result = await ssrTransformSimple (
148
+ `import { fn } from 'vue';class A { fn() { fn() } }`
172
149
)
173
- expect ( result . code ) . toMatchInlineSnapshot ( `
150
+ expect ( result ? .code ) . toMatchInlineSnapshot ( `
174
151
"const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\");
175
152
class A { fn() { __vite_ssr_import_0__.fn() } }"
176
153
` )
177
- expect ( result . deps ) . toEqual ( [ 'vue' ] )
154
+ expect ( result ? .deps ) . toEqual ( [ 'vue' ] )
178
155
} )
179
156
180
157
test ( 'do not rewrite when variable is in scope' , async ( ) => {
181
- const result = await ssrTransform (
182
- `import { fn } from 'vue';function A(){ const fn = () => {}; return { fn }; }` ,
183
- null ,
184
- null
158
+ const result = await ssrTransformSimple (
159
+ `import { fn } from 'vue';function A(){ const fn = () => {}; return { fn }; }`
185
160
)
186
- expect ( result . code ) . toMatchInlineSnapshot ( `
161
+ expect ( result ? .code ) . toMatchInlineSnapshot ( `
187
162
"const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\");
188
163
function A(){ const fn = () => {}; return { fn }; }"
189
164
` )
190
- expect ( result . deps ) . toEqual ( [ 'vue' ] )
165
+ expect ( result ? .deps ) . toEqual ( [ 'vue' ] )
191
166
} )
192
167
193
168
// #5472
194
169
test ( 'do not rewrite when variable is in scope with object destructuring' , async ( ) => {
195
- const result = await ssrTransform (
196
- `import { fn } from 'vue';function A(){ let {fn, test} = {fn: 'foo', test: 'bar'}; return { fn }; }` ,
197
- null ,
198
- null
170
+ const result = await ssrTransformSimple (
171
+ `import { fn } from 'vue';function A(){ let {fn, test} = {fn: 'foo', test: 'bar'}; return { fn }; }`
199
172
)
200
- expect ( result . code ) . toMatchInlineSnapshot ( `
173
+ expect ( result ? .code ) . toMatchInlineSnapshot ( `
201
174
"const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\");
202
175
function A(){ let {fn, test} = {fn: 'foo', test: 'bar'}; return { fn }; }"
203
176
` )
204
- expect ( result . deps ) . toEqual ( [ 'vue' ] )
177
+ expect ( result ? .deps ) . toEqual ( [ 'vue' ] )
205
178
} )
206
179
207
180
// #5472
208
181
test ( 'do not rewrite when variable is in scope with array destructuring' , async ( ) => {
209
- const result = await ssrTransform (
210
- `import { fn } from 'vue';function A(){ let [fn, test] = ['foo', 'bar']; return { fn }; }` ,
211
- null ,
212
- null
182
+ const result = await ssrTransformSimple (
183
+ `import { fn } from 'vue';function A(){ let [fn, test] = ['foo', 'bar']; return { fn }; }`
213
184
)
214
- expect ( result . code ) . toMatchInlineSnapshot ( `
185
+ expect ( result ? .code ) . toMatchInlineSnapshot ( `
215
186
"const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\");
216
187
function A(){ let [fn, test] = ['foo', 'bar']; return { fn }; }"
217
188
` )
218
- expect ( result . deps ) . toEqual ( [ 'vue' ] )
189
+ expect ( result ? .deps ) . toEqual ( [ 'vue' ] )
219
190
} )
220
191
221
192
// #5727
222
193
test ( 'rewrite variable in string interpolation in function nested arguments' , async ( ) => {
223
- const result = await ssrTransform (
224
- `import { fn } from 'vue';function A({foo = \`test\${fn}\`} = {}){ return {}; }` ,
225
- null ,
226
- null
194
+ const result = await ssrTransformSimple (
195
+ `import { fn } from 'vue';function A({foo = \`test\${fn}\`} = {}){ return {}; }`
227
196
)
228
- expect ( result . code ) . toMatchInlineSnapshot ( `
197
+ expect ( result ? .code ) . toMatchInlineSnapshot ( `
229
198
"const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\");
230
199
function A({foo = \`test\${__vite_ssr_import_0__.fn}\`} = {}){ return {}; }"
231
200
` )
232
- expect ( result . deps ) . toEqual ( [ 'vue' ] )
201
+ expect ( result ? .deps ) . toEqual ( [ 'vue' ] )
233
202
} )
234
203
235
204
// #6520
236
205
test ( 'rewrite variables in default value of destructuring params' , async ( ) => {
237
- const result = await ssrTransform (
238
- `import { fn } from 'vue';function A({foo = fn}){ return {}; }` ,
239
- null ,
240
- null
206
+ const result = await ssrTransformSimple (
207
+ `import { fn } from 'vue';function A({foo = fn}){ return {}; }`
241
208
)
242
- expect ( result . code ) . toMatchInlineSnapshot ( `
209
+ expect ( result ? .code ) . toMatchInlineSnapshot ( `
243
210
"const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\");
244
211
function A({foo = __vite_ssr_import_0__.fn}){ return {}; }"
245
212
` )
246
- expect ( result . deps ) . toEqual ( [ 'vue' ] )
213
+ expect ( result ? .deps ) . toEqual ( [ 'vue' ] )
247
214
} )
248
215
249
216
test ( 'do not rewrite when function declaration is in scope' , async ( ) => {
250
- const result = await ssrTransform (
251
- `import { fn } from 'vue';function A(){ function fn() {}; return { fn }; }` ,
252
- null ,
253
- null
217
+ const result = await ssrTransformSimple (
218
+ `import { fn } from 'vue';function A(){ function fn() {}; return { fn }; }`
254
219
)
255
- expect ( result . code ) . toMatchInlineSnapshot ( `
220
+ expect ( result ? .code ) . toMatchInlineSnapshot ( `
256
221
"const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\");
257
222
function A(){ function fn() {}; return { fn }; }"
258
223
` )
259
- expect ( result . deps ) . toEqual ( [ 'vue' ] )
224
+ expect ( result ? .deps ) . toEqual ( [ 'vue' ] )
260
225
} )
261
226
262
227
test ( 'do not rewrite catch clause' , async ( ) => {
263
- const result = await ssrTransform (
264
- `import {error} from './dependency';try {} catch(error) {}` ,
265
- null ,
266
- null
228
+ const result = await ssrTransformSimple (
229
+ `import {error} from './dependency';try {} catch(error) {}`
267
230
)
268
- expect ( result . code ) . toMatchInlineSnapshot ( `
231
+ expect ( result ? .code ) . toMatchInlineSnapshot ( `
269
232
"const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"./dependency\\");
270
233
try {} catch(error) {}"
271
234
` )
272
- expect ( result . deps ) . toEqual ( [ './dependency' ] )
235
+ expect ( result ? .deps ) . toEqual ( [ './dependency' ] )
273
236
} )
274
237
275
238
// #2221
276
239
test ( 'should declare variable for imported super class' , async ( ) => {
277
240
expect (
278
- (
279
- await ssrTransform (
280
- `import { Foo } from './dependency';` + `class A extends Foo {}` ,
281
- null ,
282
- null
283
- )
284
- ) . code
241
+ await ssrTransformSimpleCode (
242
+ `import { Foo } from './dependency';` + `class A extends Foo {}`
243
+ )
285
244
) . toMatchInlineSnapshot ( `
286
245
"const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"./dependency\\");
287
246
const Foo = __vite_ssr_import_0__.Foo;
@@ -291,15 +250,11 @@ test('should declare variable for imported super class', async () => {
291
250
// exported classes: should prepend the declaration at root level, before the
292
251
// first class that uses the binding
293
252
expect (
294
- (
295
- await ssrTransform (
296
- `import { Foo } from './dependency';` +
297
- `export default class A extends Foo {}\n` +
298
- `export class B extends Foo {}` ,
299
- null ,
300
- null
301
- )
302
- ) . code
253
+ await ssrTransformSimpleCode (
254
+ `import { Foo } from './dependency';` +
255
+ `export default class A extends Foo {}\n` +
256
+ `export class B extends Foo {}`
257
+ )
303
258
) . toMatchInlineSnapshot ( `
304
259
"const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"./dependency\\");
305
260
const Foo = __vite_ssr_import_0__.Foo;
@@ -313,42 +268,32 @@ test('should declare variable for imported super class', async () => {
313
268
// #4049
314
269
test ( 'should handle default export variants' , async ( ) => {
315
270
// default anonymous functions
316
- expect (
317
- ( await ssrTransform ( `export default function() {}\n` , null , null ) ) . code
318
- ) . toMatchInlineSnapshot ( `
271
+ expect ( await ssrTransformSimpleCode ( `export default function() {}\n` ) )
272
+ . toMatchInlineSnapshot ( `
319
273
"__vite_ssr_exports__.default = function() {}
320
274
"
321
275
` )
322
276
// default anonymous class
323
- expect ( ( await ssrTransform ( `export default class {}\n` , null , null ) ) . code )
277
+ expect ( await ssrTransformSimpleCode ( `export default class {}\n` ) )
324
278
. toMatchInlineSnapshot ( `
325
279
"__vite_ssr_exports__.default = class {}
326
280
"
327
281
` )
328
282
// default named functions
329
283
expect (
330
- (
331
- await ssrTransform (
332
- `export default function foo() {}\n` +
333
- `foo.prototype = Object.prototype;` ,
334
- null ,
335
- null
336
- )
337
- ) . code
284
+ await ssrTransformSimpleCode (
285
+ `export default function foo() {}\n` + `foo.prototype = Object.prototype;`
286
+ )
338
287
) . toMatchInlineSnapshot ( `
339
288
"function foo() {}
340
289
foo.prototype = Object.prototype;
341
290
Object.defineProperty(__vite_ssr_exports__, \\"default\\", { enumerable: true, configurable: true, value: foo });"
342
291
` )
343
292
// default named classes
344
293
expect (
345
- (
346
- await ssrTransform (
347
- `export default class A {}\n` + `export class B extends A {}` ,
348
- null ,
349
- null
350
- )
351
- ) . code
294
+ await ssrTransformSimpleCode (
295
+ `export default class A {}\n` + `export class B extends A {}`
296
+ )
352
297
) . toMatchInlineSnapshot ( `
353
298
"class A {}
354
299
class B extends A {}
@@ -358,27 +303,30 @@ test('should handle default export variants', async () => {
358
303
} )
359
304
360
305
test ( 'sourcemap source' , async ( ) => {
361
- expect (
362
- ( await ssrTransform ( `export const a = 1` , null , 'input.js' ) ) . map . sources
363
- ) . toStrictEqual ( [ 'input.js' ] )
306
+ const map = (
307
+ await ssrTransform (
308
+ `export const a = 1` ,
309
+ null ,
310
+ 'input.js' ,
311
+ 'export const a = 1 /* */'
312
+ )
313
+ ) ?. map
314
+ expect ( map ?. sources ) . toStrictEqual ( [ 'input.js' ] )
315
+ expect ( map ?. sourcesContent ) . toStrictEqual ( [ 'export const a = 1 /* */' ] )
364
316
} )
365
317
366
318
test ( 'overwrite bindings' , async ( ) => {
367
319
expect (
368
- (
369
- await ssrTransform (
370
- `import { inject } from 'vue';` +
371
- `const a = { inject }\n` +
372
- `const b = { test: inject }\n` +
373
- `function c() { const { test: inject } = { test: true }; console.log(inject) }\n` +
374
- `const d = inject\n` +
375
- `function f() { console.log(inject) }\n` +
376
- `function e() { const { inject } = { inject: true } }\n` +
377
- `function g() { const f = () => { const inject = true }; console.log(inject) }\n` ,
378
- null ,
379
- null
380
- )
381
- ) . code
320
+ await ssrTransformSimpleCode (
321
+ `import { inject } from 'vue';` +
322
+ `const a = { inject }\n` +
323
+ `const b = { test: inject }\n` +
324
+ `function c() { const { test: inject } = { test: true }; console.log(inject) }\n` +
325
+ `const d = inject\n` +
326
+ `function f() { console.log(inject) }\n` +
327
+ `function e() { const { inject } = { inject: true } }\n` +
328
+ `function g() { const f = () => { const inject = true }; console.log(inject) }\n`
329
+ )
382
330
) . toMatchInlineSnapshot ( `
383
331
"const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\");
384
332
const a = { inject: __vite_ssr_import_0__.inject }
@@ -394,24 +342,20 @@ test('overwrite bindings', async () => {
394
342
395
343
test ( 'Empty array pattern' , async ( ) => {
396
344
expect (
397
- ( await ssrTransform ( `const [, LHS, RHS] = inMatch;` , null , null ) ) . code
345
+ await ssrTransformSimpleCode ( `const [, LHS, RHS] = inMatch;` )
398
346
) . toMatchInlineSnapshot ( `"const [, LHS, RHS] = inMatch;"` )
399
347
} )
400
348
401
349
test ( 'function argument destructure' , async ( ) => {
402
350
expect (
403
- (
404
- await ssrTransform (
405
- `
351
+ await ssrTransformSimpleCode (
352
+ `
406
353
import { foo, bar } from 'foo'
407
354
const a = ({ _ = foo() }) => {}
408
355
function b({ _ = bar() }) {}
409
356
function c({ _ = bar() + foo() }) {}
410
- ` ,
411
- null ,
412
- null
413
- )
414
- ) . code
357
+ `
358
+ )
415
359
) . toMatchInlineSnapshot ( `
416
360
"
417
361
const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"foo\\");
@@ -425,19 +369,15 @@ function c({ _ = bar() + foo() }) {}
425
369
426
370
test ( 'object destructure alias' , async ( ) => {
427
371
expect (
428
- (
429
- await ssrTransform (
430
- `
372
+ await ssrTransformSimpleCode (
373
+ `
431
374
import { n } from 'foo'
432
375
const a = () => {
433
376
const { type: n = 'bar' } = {}
434
377
console.log(n)
435
378
}
436
- ` ,
437
- null ,
438
- null
439
- )
440
- ) . code
379
+ `
380
+ )
441
381
) . toMatchInlineSnapshot ( `
442
382
"
443
383
const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"foo\\");
@@ -452,9 +392,8 @@ const a = () => {
452
392
453
393
test ( 'nested object destructure alias' , async ( ) => {
454
394
expect (
455
- (
456
- await ssrTransform (
457
- `
395
+ await ssrTransformSimpleCode (
396
+ `
458
397
import { remove, add, get, set, rest, objRest } from 'vue'
459
398
460
399
function a() {
@@ -479,11 +418,8 @@ get()
479
418
set()
480
419
rest()
481
420
objRest()
482
- ` ,
483
- null ,
484
- null
485
- )
486
- ) . code
421
+ `
422
+ )
487
423
) . toMatchInlineSnapshot ( `
488
424
"
489
425
const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\");
@@ -517,20 +453,16 @@ objRest()
517
453
518
454
test ( 'class props' , async ( ) => {
519
455
expect (
520
- (
521
- await ssrTransform (
522
- `
456
+ await ssrTransformSimpleCode (
457
+ `
523
458
import { remove, add } from 'vue'
524
459
525
460
class A {
526
461
remove = 1
527
462
add = null
528
463
}
529
- ` ,
530
- null ,
531
- null
532
- )
533
- ) . code
464
+ `
465
+ )
534
466
) . toMatchInlineSnapshot ( `
535
467
"
536
468
const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\");
@@ -548,9 +480,8 @@ class A {
548
480
549
481
test ( 'class methods' , async ( ) => {
550
482
expect (
551
- (
552
- await ssrTransform (
553
- `
483
+ await ssrTransformSimpleCode (
484
+ `
554
485
import foo from 'foo'
555
486
556
487
const bar = 'bar'
@@ -562,11 +493,8 @@ class A {
562
493
#foo() {}
563
494
bar(foo) {}
564
495
}
565
- ` ,
566
- null ,
567
- null
568
- )
569
- ) . code
496
+ `
497
+ )
570
498
) . toMatchInlineSnapshot ( `
571
499
"
572
500
const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"foo\\");
@@ -587,9 +515,8 @@ class A {
587
515
588
516
test ( 'declare scope' , async ( ) => {
589
517
expect (
590
- (
591
- await ssrTransform (
592
- `
518
+ await ssrTransformSimpleCode (
519
+ `
593
520
import { aaa, bbb, ccc, ddd } from 'vue'
594
521
595
522
function foobar() {
@@ -612,11 +539,8 @@ function foobar() {
612
539
613
540
aaa()
614
541
bbb()
615
- ` ,
616
- null ,
617
- null
618
- )
619
- ) . code
542
+ `
543
+ )
620
544
) . toMatchInlineSnapshot ( `
621
545
"
622
546
const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\");
@@ -661,7 +585,7 @@ test('jsx', async () => {
661
585
`
662
586
const id = '/foo.jsx'
663
587
const result = await transformWithEsbuild ( code , id )
664
- expect ( ( await ssrTransform ( result . code , null , '/foo.jsx' ) ) . code )
588
+ expect ( await ssrTransformSimpleCode ( result . code , '/foo.jsx' ) )
665
589
. toMatchInlineSnapshot ( `
666
590
"const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"react\\");
667
591
@@ -676,17 +600,13 @@ test('jsx', async () => {
676
600
677
601
test ( 'continuous exports' , async ( ) => {
678
602
expect (
679
- (
680
- await ssrTransform (
681
- `
603
+ await ssrTransformSimpleCode (
604
+ `
682
605
export function fn1() {
683
606
}export function fn2() {
684
607
}
685
- ` ,
686
- null ,
687
- null
688
- )
689
- ) . code
608
+ `
609
+ )
690
610
) . toMatchInlineSnapshot ( `
691
611
"
692
612
function fn1() {
@@ -710,28 +630,24 @@ export default (function getRandom() {
710
630
});
711
631
` . trim ( )
712
632
713
- expect ( ( await ssrTransform ( code , null , null ) ) . code ) . toMatchInlineSnapshot ( `
633
+ expect ( await ssrTransformSimpleCode ( code ) ) . toMatchInlineSnapshot ( `
714
634
"__vite_ssr_exports__.default = (function getRandom() {
715
635
return Math.random();
716
636
});"
717
637
` )
718
638
719
639
expect (
720
- ( await ssrTransform ( `export default (class A {});` , null , null ) ) . code
640
+ await ssrTransformSimpleCode ( `export default (class A {});` )
721
641
) . toMatchInlineSnapshot ( `"__vite_ssr_exports__.default = (class A {});"` )
722
642
} )
723
643
724
644
// #8002
725
645
test ( 'with hashbang' , async ( ) => {
726
646
expect (
727
- (
728
- await ssrTransform (
729
- `#!/usr/bin/env node
730
- console.log("it can parse the hashbang")` ,
731
- null ,
732
- null
733
- )
734
- ) . code
647
+ await ssrTransformSimpleCode (
648
+ `#!/usr/bin/env node
649
+ console.log("it can parse the hashbang")`
650
+ )
735
651
) . toMatchInlineSnapshot ( `
736
652
"#!/usr/bin/env node
737
653
console.log(\\"it can parse the hashbang\\")"
0 commit comments