mirror of
https://github.com/vitejs/vite.git
synced 2024-11-22 07:09:05 +00:00
fix(ssr): use appendRight for import (#9554)
This commit is contained in:
parent
a6b12f8c46
commit
dfec6ca71a
@ -125,6 +125,18 @@ test('export default', async () => {
|
||||
).toMatchInlineSnapshot(`"__vite_ssr_exports__.default = {}"`)
|
||||
})
|
||||
|
||||
test('export then import minified', async () => {
|
||||
expect(
|
||||
await ssrTransformSimpleCode(
|
||||
`export * from 'vue';import {createApp} from 'vue';`
|
||||
)
|
||||
).toMatchInlineSnapshot(`
|
||||
"const __vite_ssr_import_1__ = await __vite_ssr_import__(\\"vue\\");
|
||||
__vite_ssr_exportAll__(__vite_ssr_import_1__);const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\");
|
||||
"
|
||||
`)
|
||||
})
|
||||
|
||||
test('import.meta', async () => {
|
||||
expect(
|
||||
await ssrTransformSimpleCode(`console.log(import.meta.url)`)
|
||||
|
@ -94,7 +94,7 @@ async function ssrTransformScript(
|
||||
function defineImport(node: Node, source: string) {
|
||||
deps.add(source)
|
||||
const importId = `__vite_ssr_import_${uid++}__`
|
||||
s.appendLeft(
|
||||
s.appendRight(
|
||||
node.start,
|
||||
`const ${importId} = await ${ssrImportKey}(${JSON.stringify(source)});\n`
|
||||
)
|
||||
@ -115,6 +115,7 @@ async function ssrTransformScript(
|
||||
// import { baz } from 'foo' --> baz -> __import_foo__.baz
|
||||
// import * as ok from 'foo' --> ok -> __import_foo__
|
||||
if (node.type === 'ImportDeclaration') {
|
||||
s.remove(node.start, node.end)
|
||||
const importId = defineImport(node, node.source.value as string)
|
||||
for (const spec of node.specifiers) {
|
||||
if (spec.type === 'ImportSpecifier') {
|
||||
@ -129,7 +130,6 @@ async function ssrTransformScript(
|
||||
idToImportMap.set(spec.local.name, importId)
|
||||
}
|
||||
}
|
||||
s.remove(node.start, node.end)
|
||||
}
|
||||
}
|
||||
|
||||
@ -207,13 +207,11 @@ async function ssrTransformScript(
|
||||
|
||||
// export * from './foo'
|
||||
if (node.type === 'ExportAllDeclaration') {
|
||||
s.remove(node.start, node.end)
|
||||
const importId = defineImport(node, node.source.value as string)
|
||||
if (node.exported) {
|
||||
const importId = defineImport(node, node.source.value as string)
|
||||
s.remove(node.start, node.end)
|
||||
defineExport(node.end, node.exported.name, `${importId}`)
|
||||
} else {
|
||||
const importId = defineImport(node, node.source.value as string)
|
||||
s.remove(node.start, node.end)
|
||||
s.appendLeft(node.end, `${ssrExportAllKey}(${importId});`)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user