Skip to content

Commit 7381d27

Browse files
hglaleclarson
andauthored
fix(ssr): not flatten export * as (fix #3934) (#3954)
Co-authored-by: Alec Larson <[email protected]>
1 parent bc86464 commit 7381d27

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,15 @@ test('export * from', async () => {
119119
`)
120120
})
121121

122+
test('export * as from', async () => {
123+
expect((await ssrTransform(`export * as foo from 'vue'`, null, null)).code)
124+
.toMatchInlineSnapshot(`
125+
"const __vite_ssr_import_0__ = __vite_ssr_import__(\\"vue\\")
126+
127+
Object.defineProperty(__vite_ssr_exports__, \\"foo\\", { enumerable: true, configurable: true, get(){ return __vite_ssr_import_0__ }})"
128+
`)
129+
})
130+
122131
test('export default', async () => {
123132
expect(
124133
(await ssrTransform(`export default {}`, null, null)).code

packages/vite/src/node/ssr/ssrTransform.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,15 @@ export async function ssrTransform(
133133

134134
// export * from './foo'
135135
if (node.type === 'ExportAllDeclaration') {
136-
const importId = defineImport(node, node.source.value as string)
137-
s.remove(node.start, node.end)
138-
s.append(`\n${ssrExportAllKey}(${importId})`)
136+
if ((node as any).exported) {
137+
const importId = defineImport(node, node.source.value as string)
138+
defineExport((node as any).exported.name, `${importId}`)
139+
s.remove(node.start, node.end)
140+
} else {
141+
const importId = defineImport(node, node.source.value as string)
142+
s.remove(node.start, node.end)
143+
s.append(`\n${ssrExportAllKey}(${importId})`)
144+
}
139145
}
140146
}
141147

0 commit comments

Comments
 (0)