Skip to content

Commit

Permalink
fix(ssr): fix transform error due to export all id scope (#19331)
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa authored Feb 1, 2025
1 parent f19ffbc commit e28bce2
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 @@ -127,6 +127,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 @@ -719,7 +719,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 e28bce2

Please sign in to comment.