Skip to content

Commit

Permalink
fix(ssr): fix export all id scope in ssr transform
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Feb 1, 2025
1 parent 3aa10b7 commit 85e77c8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
38 changes: 38 additions & 0 deletions packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,44 @@ test('export * as from', async () => {
`)
})

test('re-export by imported name', async () => {
expect(
await ssrTransformSimpleCode(`\
import * as foo from 'foo'
export * as foo from 'foo'
`),
).toMatchInlineSnapshot(`
"const __vite_ssr_import_0__ = await __vite_ssr_import__("foo");
const __vite_ssr_import_1__ = await __vite_ssr_import__("foo");
Object.defineProperty(__vite_ssr_exports__, "foo", { enumerable: true, configurable: true, get(){ return __vite_ssr_import_1__ }});
"
`)

expect(
await ssrTransformSimpleCode(`\
import { foo } from 'foo'
export { foo } from 'foo'
`),
).toMatchInlineSnapshot(`
"const __vite_ssr_import_0__ = await __vite_ssr_import__("foo", {"importedNames":["foo"]});
const __vite_ssr_import_1__ = await __vite_ssr_import__("foo", {"importedNames":["foo"]});
Object.defineProperty(__vite_ssr_exports__, "foo", { enumerable: true, configurable: true, get(){ return __vite_ssr_import_1__.foo }});
"
`)

expect(
await ssrTransformSimpleCode(`\
import { foo } from 'foo'
export { foo as foo } from 'foo'
`),
).toMatchInlineSnapshot(`
"const __vite_ssr_import_0__ = await __vite_ssr_import__("foo", {"importedNames":["foo"]});
const __vite_ssr_import_1__ = await __vite_ssr_import__("foo", {"importedNames":["foo"]});
Object.defineProperty(__vite_ssr_exports__, "foo", { enumerable: true, configurable: true, get(){ return __vite_ssr_import_1__.foo }});
"
`)
})

test('export * as from arbitrary module namespace identifier', async () => {
expect(
await ssrTransformSimpleCode(`export * as "arbitrary string" from 'vue'`),
Expand Down
7 changes: 6 additions & 1 deletion packages/vite/src/node/ssr/ssrTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,12 @@ function isRefIdentifier(id: Identifier, parent: _Node, parentStack: _Node[]) {
return false
}

if (parent.type === 'ExportSpecifier') {
// export { id } from "lib"
// export * as id from "lib"
if (
parent.type === 'ExportSpecifier' ||
parent.type === 'ExportAllDeclaration'
) {
return false
}

Expand Down

0 comments on commit 85e77c8

Please sign in to comment.