@@ -11,7 +11,7 @@ test('default import', async () => {
11
11
expect (
12
12
await ssrTransformSimpleCode ( `import foo from 'vue';console.log(foo.bar)` ) ,
13
13
) . toMatchInlineSnapshot ( `
14
- "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\");
14
+ "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\", {\\"importedNames\\":[\\"default\\"]} );
15
15
console.log(__vite_ssr_import_0__.default.bar)"
16
16
` )
17
17
} )
@@ -22,7 +22,7 @@ test('named import', async () => {
22
22
`import { ref } from 'vue';function foo() { return ref(0) }` ,
23
23
) ,
24
24
) . toMatchInlineSnapshot ( `
25
- "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\", {\\"namedImportSpecifiers \\":[\\"ref\\"]});
25
+ "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\", {\\"importedNames \\":[\\"ref\\"]});
26
26
function foo() { return __vite_ssr_import_0__.ref(0) }"
27
27
` )
28
28
} )
@@ -77,7 +77,7 @@ test('export named from', async () => {
77
77
expect (
78
78
await ssrTransformSimpleCode ( `export { ref, computed as c } from 'vue'` ) ,
79
79
) . toMatchInlineSnapshot ( `
80
- "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\", {\\"namedImportSpecifiers \\":[\\"ref\\",\\"computed\\"]});
80
+ "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\", {\\"importedNames \\":[\\"ref\\",\\"computed\\"]});
81
81
82
82
Object.defineProperty(__vite_ssr_exports__, \\"ref\\", { enumerable: true, configurable: true, get(){ return __vite_ssr_import_0__.ref }});
83
83
Object.defineProperty(__vite_ssr_exports__, \\"c\\", { enumerable: true, configurable: true, get(){ return __vite_ssr_import_0__.computed }});"
@@ -90,7 +90,7 @@ test('named exports of imported binding', async () => {
90
90
`import {createApp} from 'vue';export {createApp}` ,
91
91
) ,
92
92
) . toMatchInlineSnapshot ( `
93
- "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\", {\\"namedImportSpecifiers \\":[\\"createApp\\"]});
93
+ "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\", {\\"importedNames \\":[\\"createApp\\"]});
94
94
95
95
Object.defineProperty(__vite_ssr_exports__, \\"createApp\\", { enumerable: true, configurable: true, get(){ return __vite_ssr_import_0__.createApp }});"
96
96
` )
@@ -132,7 +132,7 @@ test('export then import minified', async () => {
132
132
`export * from 'vue';import {createApp} from 'vue';` ,
133
133
) ,
134
134
) . toMatchInlineSnapshot ( `
135
- "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\", {\\"namedImportSpecifiers \\":[\\"createApp\\"]});
135
+ "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\", {\\"importedNames \\":[\\"createApp\\"]});
136
136
const __vite_ssr_import_1__ = await __vite_ssr_import__(\\"vue\\");
137
137
__vite_ssr_exportAll__(__vite_ssr_import_1__);
138
138
"
@@ -145,7 +145,7 @@ test('hoist import to top', async () => {
145
145
`path.resolve('server.js');import path from 'node:path';` ,
146
146
) ,
147
147
) . toMatchInlineSnapshot ( `
148
- "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"node:path\\");
148
+ "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"node:path\\", {\\"importedNames\\":[\\"default\\"]} );
149
149
__vite_ssr_import_0__.default.resolve('server.js');"
150
150
` )
151
151
} )
@@ -173,7 +173,7 @@ test('do not rewrite method definition', async () => {
173
173
`import { fn } from 'vue';class A { fn() { fn() } }` ,
174
174
)
175
175
expect ( result ?. code ) . toMatchInlineSnapshot ( `
176
- "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\", {\\"namedImportSpecifiers \\":[\\"fn\\"]});
176
+ "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\", {\\"importedNames \\":[\\"fn\\"]});
177
177
class A { fn() { __vite_ssr_import_0__.fn() } }"
178
178
` )
179
179
expect ( result ?. deps ) . toEqual ( [ 'vue' ] )
@@ -184,7 +184,7 @@ test('do not rewrite when variable is in scope', async () => {
184
184
`import { fn } from 'vue';function A(){ const fn = () => {}; return { fn }; }` ,
185
185
)
186
186
expect ( result ?. code ) . toMatchInlineSnapshot ( `
187
- "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\", {\\"namedImportSpecifiers \\":[\\"fn\\"]});
187
+ "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\", {\\"importedNames \\":[\\"fn\\"]});
188
188
function A(){ const fn = () => {}; return { fn }; }"
189
189
` )
190
190
expect ( result ?. deps ) . toEqual ( [ 'vue' ] )
@@ -196,7 +196,7 @@ test('do not rewrite when variable is in scope with object destructuring', async
196
196
`import { fn } from 'vue';function A(){ let {fn, test} = {fn: 'foo', test: 'bar'}; return { fn }; }` ,
197
197
)
198
198
expect ( result ?. code ) . toMatchInlineSnapshot ( `
199
- "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\", {\\"namedImportSpecifiers \\":[\\"fn\\"]});
199
+ "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\", {\\"importedNames \\":[\\"fn\\"]});
200
200
function A(){ let {fn, test} = {fn: 'foo', test: 'bar'}; return { fn }; }"
201
201
` )
202
202
expect ( result ?. deps ) . toEqual ( [ 'vue' ] )
@@ -208,7 +208,7 @@ test('do not rewrite when variable is in scope with array destructuring', async
208
208
`import { fn } from 'vue';function A(){ let [fn, test] = ['foo', 'bar']; return { fn }; }` ,
209
209
)
210
210
expect ( result ?. code ) . toMatchInlineSnapshot ( `
211
- "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\", {\\"namedImportSpecifiers \\":[\\"fn\\"]});
211
+ "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\", {\\"importedNames \\":[\\"fn\\"]});
212
212
function A(){ let [fn, test] = ['foo', 'bar']; return { fn }; }"
213
213
` )
214
214
expect ( result ?. deps ) . toEqual ( [ 'vue' ] )
@@ -220,7 +220,7 @@ test('rewrite variable in string interpolation in function nested arguments', as
220
220
`import { fn } from 'vue';function A({foo = \`test\${fn}\`} = {}){ return {}; }` ,
221
221
)
222
222
expect ( result ?. code ) . toMatchInlineSnapshot ( `
223
- "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\", {\\"namedImportSpecifiers \\":[\\"fn\\"]});
223
+ "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\", {\\"importedNames \\":[\\"fn\\"]});
224
224
function A({foo = \`test\${__vite_ssr_import_0__.fn}\`} = {}){ return {}; }"
225
225
` )
226
226
expect ( result ?. deps ) . toEqual ( [ 'vue' ] )
@@ -232,7 +232,7 @@ test('rewrite variables in default value of destructuring params', async () => {
232
232
`import { fn } from 'vue';function A({foo = fn}){ return {}; }` ,
233
233
)
234
234
expect ( result ?. code ) . toMatchInlineSnapshot ( `
235
- "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\", {\\"namedImportSpecifiers \\":[\\"fn\\"]});
235
+ "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\", {\\"importedNames \\":[\\"fn\\"]});
236
236
function A({foo = __vite_ssr_import_0__.fn}){ return {}; }"
237
237
` )
238
238
expect ( result ?. deps ) . toEqual ( [ 'vue' ] )
@@ -243,7 +243,7 @@ test('do not rewrite when function declaration is in scope', async () => {
243
243
`import { fn } from 'vue';function A(){ function fn() {}; return { fn }; }` ,
244
244
)
245
245
expect ( result ?. code ) . toMatchInlineSnapshot ( `
246
- "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\", {\\"namedImportSpecifiers \\":[\\"fn\\"]});
246
+ "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\", {\\"importedNames \\":[\\"fn\\"]});
247
247
function A(){ function fn() {}; return { fn }; }"
248
248
` )
249
249
expect ( result ?. deps ) . toEqual ( [ 'vue' ] )
@@ -254,7 +254,7 @@ test('do not rewrite catch clause', async () => {
254
254
`import {error} from './dependency';try {} catch(error) {}` ,
255
255
)
256
256
expect ( result ?. code ) . toMatchInlineSnapshot ( `
257
- "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"./dependency\\", {\\"namedImportSpecifiers \\":[\\"error\\"]});
257
+ "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"./dependency\\", {\\"importedNames \\":[\\"error\\"]});
258
258
try {} catch(error) {}"
259
259
` )
260
260
expect ( result ?. deps ) . toEqual ( [ './dependency' ] )
@@ -267,7 +267,7 @@ test('should declare variable for imported super class', async () => {
267
267
`import { Foo } from './dependency';` + `class A extends Foo {}` ,
268
268
) ,
269
269
) . toMatchInlineSnapshot ( `
270
- "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"./dependency\\", {\\"namedImportSpecifiers \\":[\\"Foo\\"]});
270
+ "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"./dependency\\", {\\"importedNames \\":[\\"Foo\\"]});
271
271
const Foo = __vite_ssr_import_0__.Foo;
272
272
class A extends Foo {}"
273
273
` )
@@ -281,7 +281,7 @@ test('should declare variable for imported super class', async () => {
281
281
`export class B extends Foo {}` ,
282
282
) ,
283
283
) . toMatchInlineSnapshot ( `
284
- "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"./dependency\\", {\\"namedImportSpecifiers \\":[\\"Foo\\"]});
284
+ "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"./dependency\\", {\\"importedNames \\":[\\"Foo\\"]});
285
285
const Foo = __vite_ssr_import_0__.Foo;
286
286
class A extends Foo {}
287
287
class B extends Foo {}
@@ -354,7 +354,7 @@ test('overwrite bindings', async () => {
354
354
`function g() { const f = () => { const inject = true }; console.log(inject) }\n` ,
355
355
) ,
356
356
) . toMatchInlineSnapshot ( `
357
- "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\", {\\"namedImportSpecifiers \\":[\\"inject\\"]});
357
+ "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\", {\\"importedNames \\":[\\"inject\\"]});
358
358
const a = { inject: __vite_ssr_import_0__.inject }
359
359
const b = { test: __vite_ssr_import_0__.inject }
360
360
function c() { const { test: inject } = { test: true }; console.log(inject) }
@@ -383,7 +383,7 @@ function c({ _ = bar() + foo() }) {}
383
383
` ,
384
384
) ,
385
385
) . toMatchInlineSnapshot ( `
386
- "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"foo\\", {\\"namedImportSpecifiers \\":[\\"foo\\",\\"bar\\"]});
386
+ "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"foo\\", {\\"importedNames \\":[\\"foo\\",\\"bar\\"]});
387
387
388
388
389
389
const a = ({ _ = __vite_ssr_import_0__.foo() }) => {}
@@ -405,7 +405,7 @@ const a = () => {
405
405
` ,
406
406
) ,
407
407
) . toMatchInlineSnapshot ( `
408
- "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"foo\\", {\\"namedImportSpecifiers \\":[\\"n\\"]});
408
+ "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"foo\\", {\\"importedNames \\":[\\"n\\"]});
409
409
410
410
411
411
const a = () => {
@@ -428,7 +428,7 @@ const foo = {}
428
428
` ,
429
429
) ,
430
430
) . toMatchInlineSnapshot ( `
431
- "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"foo\\", {\\"namedImportSpecifiers \\":[\\"n\\",\\"m\\"]});
431
+ "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"foo\\", {\\"importedNames \\":[\\"n\\",\\"m\\"]});
432
432
433
433
434
434
const foo = {}
@@ -471,7 +471,7 @@ objRest()
471
471
` ,
472
472
) ,
473
473
) . toMatchInlineSnapshot ( `
474
- "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\", {\\"namedImportSpecifiers \\":[\\"remove\\",\\"add\\",\\"get\\",\\"set\\",\\"rest\\",\\"objRest\\"]});
474
+ "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\", {\\"importedNames \\":[\\"remove\\",\\"add\\",\\"get\\",\\"set\\",\\"rest\\",\\"objRest\\"]});
475
475
476
476
477
477
@@ -521,7 +521,7 @@ const obj = {
521
521
` ,
522
522
) ,
523
523
) . toMatchInlineSnapshot ( `
524
- "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"foo\\");
524
+ "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"foo\\", {\\"importedNames\\":[\\"default\\"]} );
525
525
526
526
527
527
@@ -553,7 +553,7 @@ class A {
553
553
` ,
554
554
) ,
555
555
) . toMatchInlineSnapshot ( `
556
- "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\", {\\"namedImportSpecifiers \\":[\\"remove\\",\\"add\\"]});
556
+ "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\", {\\"importedNames \\":[\\"remove\\",\\"add\\"]});
557
557
558
558
559
559
@@ -585,7 +585,7 @@ class A {
585
585
` ,
586
586
) ,
587
587
) . toMatchInlineSnapshot ( `
588
- "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"foo\\");
588
+ "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"foo\\", {\\"importedNames\\":[\\"default\\"]} );
589
589
590
590
591
591
@@ -631,7 +631,7 @@ bbb()
631
631
` ,
632
632
) ,
633
633
) . toMatchInlineSnapshot ( `
634
- "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\", {\\"namedImportSpecifiers \\":[\\"aaa\\",\\"bbb\\",\\"ccc\\",\\"ddd\\"]});
634
+ "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\", {\\"importedNames \\":[\\"aaa\\",\\"bbb\\",\\"ccc\\",\\"ddd\\"]});
635
635
636
636
637
637
@@ -676,8 +676,8 @@ test('jsx', async () => {
676
676
const result = await transformWithEsbuild ( code , id )
677
677
expect ( await ssrTransformSimpleCode ( result . code , '/foo.jsx' ) )
678
678
. toMatchInlineSnapshot ( `
679
- "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"react\\");
680
- const __vite_ssr_import_1__ = await __vite_ssr_import__(\\"foo\\", {\\"namedImportSpecifiers \\":[\\"Foo\\",\\"Slot\\"]});
679
+ "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"react\\", {\\"importedNames\\":[\\"default\\"]} );
680
+ const __vite_ssr_import_1__ = await __vite_ssr_import__(\\"foo\\", {\\"importedNames \\":[\\"Foo\\",\\"Slot\\"]});
681
681
682
682
683
683
function Bar({ Slot: Slot2 = /* @__PURE__ */ __vite_ssr_import_0__.default.createElement(__vite_ssr_import_1__.Foo, null) }) {
@@ -752,7 +752,7 @@ import foo from "foo"`,
752
752
) ,
753
753
) . toMatchInlineSnapshot ( `
754
754
"#!/usr/bin/env node
755
- const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"foo\\");
755
+ const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"foo\\", {\\"importedNames\\":[\\"default\\"]} );
756
756
console.log(__vite_ssr_import_0__.default);
757
757
"
758
758
` )
@@ -788,7 +788,7 @@ export class Test {
788
788
};` . trim ( )
789
789
790
790
expect ( await ssrTransformSimpleCode ( code ) ) . toMatchInlineSnapshot ( `
791
- "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"foobar\\", {\\"namedImportSpecifiers \\":[\\"foo\\",\\"bar\\"]});
791
+ "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"foobar\\", {\\"importedNames \\":[\\"foo\\",\\"bar\\"]});
792
792
793
793
if (false) {
794
794
const foo = 'foo'
@@ -830,7 +830,7 @@ function test() {
830
830
return [foo, bar]
831
831
}` ) ,
832
832
) . toMatchInlineSnapshot ( `
833
- "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"foobar\\", {\\"namedImportSpecifiers \\":[\\"foo\\",\\"bar\\"]});
833
+ "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"foobar\\", {\\"importedNames \\":[\\"foo\\",\\"bar\\"]});
834
834
835
835
836
836
function test() {
@@ -857,7 +857,7 @@ function test() {
857
857
return bar;
858
858
}` ) ,
859
859
) . toMatchInlineSnapshot ( `
860
- "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"foobar\\", {\\"namedImportSpecifiers \\":[\\"foo\\",\\"bar\\",\\"baz\\"]});
860
+ "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"foobar\\", {\\"importedNames \\":[\\"foo\\",\\"bar\\",\\"baz\\"]});
861
861
862
862
863
863
function test() {
@@ -889,7 +889,7 @@ for (const test in tests) {
889
889
console.log(test)
890
890
}` ) ,
891
891
) . toMatchInlineSnapshot ( `
892
- "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"./test.js\\", {\\"namedImportSpecifiers \\":[\\"test\\"]});
892
+ "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"./test.js\\", {\\"importedNames \\":[\\"test\\"]});
893
893
894
894
895
895
@@ -921,7 +921,7 @@ const Baz = class extends Foo {}
921
921
` ,
922
922
)
923
923
expect ( result ?. code ) . toMatchInlineSnapshot ( `
924
- "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"./foo\\", {\\"namedImportSpecifiers \\":[\\"Bar\\"]});
924
+ "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"./foo\\", {\\"importedNames \\":[\\"default\\", \\"Bar\\"]});
925
925
926
926
927
927
@@ -963,7 +963,7 @@ export * from './b'
963
963
console.log(foo + 2)
964
964
` ) ,
965
965
) . toMatchInlineSnapshot ( `
966
- "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"./foo\\", {\\"namedImportSpecifiers \\":[\\"foo\\"]});
966
+ "const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"./foo\\", {\\"importedNames \\":[\\"foo\\"]});
967
967
const __vite_ssr_import_1__ = await __vite_ssr_import__(\\"./a\\");
968
968
__vite_ssr_exportAll__(__vite_ssr_import_1__);
969
969
const __vite_ssr_import_2__ = await __vite_ssr_import__(\\"./b\\");
0 commit comments