Skip to content

Commit

Permalink
refactor(ssr): remove unused metadata code (#14711)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy authored Oct 20, 2023
1 parent 4cedcdc commit c5f2d60
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
12 changes: 6 additions & 6 deletions packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ test('export * from', async () => {
`export * from 'vue'\n` + `export * from 'react'`,
),
).toMatchInlineSnapshot(`
"const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\", {\\"isExportAll\\":true});
"const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\");
__vite_ssr_exportAll__(__vite_ssr_import_0__);
const __vite_ssr_import_1__ = await __vite_ssr_import__(\\"react\\", {\\"isExportAll\\":true});
const __vite_ssr_import_1__ = await __vite_ssr_import__(\\"react\\");
__vite_ssr_exportAll__(__vite_ssr_import_1__);
"
Expand All @@ -114,7 +114,7 @@ test('export * from', async () => {
test('export * as from', async () => {
expect(await ssrTransformSimpleCode(`export * as foo from 'vue'`))
.toMatchInlineSnapshot(`
"const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\", {\\"isExportAll\\":true});
"const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\");
Object.defineProperty(__vite_ssr_exports__, \\"foo\\", { enumerable: true, configurable: true, get(){ return __vite_ssr_import_0__ }});"
`)
Expand All @@ -133,7 +133,7 @@ test('export then import minified', async () => {
),
).toMatchInlineSnapshot(`
"const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\", {\\"namedImportSpecifiers\\":[\\"createApp\\"]});
const __vite_ssr_import_1__ = await __vite_ssr_import__(\\"vue\\", {\\"isExportAll\\":true});
const __vite_ssr_import_1__ = await __vite_ssr_import__(\\"vue\\");
__vite_ssr_exportAll__(__vite_ssr_import_1__);
"
`)
Expand Down Expand Up @@ -964,9 +964,9 @@ console.log(foo + 2)
`),
).toMatchInlineSnapshot(`
"const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"./foo\\", {\\"namedImportSpecifiers\\":[\\"foo\\"]});
const __vite_ssr_import_1__ = await __vite_ssr_import__(\\"./a\\", {\\"isExportAll\\":true});
const __vite_ssr_import_1__ = await __vite_ssr_import__(\\"./a\\");
__vite_ssr_exportAll__(__vite_ssr_import_1__);
const __vite_ssr_import_2__ = await __vite_ssr_import__(\\"./b\\", {\\"isExportAll\\":true});
const __vite_ssr_import_2__ = await __vite_ssr_import__(\\"./b\\");
__vite_ssr_exportAll__(__vite_ssr_import_2__);
console.log(__vite_ssr_import_0__.foo + 1)
Expand Down
1 change: 0 additions & 1 deletion packages/vite/src/node/ssr/ssrModuleLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ interface NodeImportResolveOptions

interface SSRImportMetadata {
isDynamicImport?: boolean
isExportAll?: boolean
namedImportSpecifiers?: string[]
}

Expand Down
6 changes: 1 addition & 5 deletions packages/vite/src/node/ssr/ssrTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ interface TransformOptions {
}

interface DefineImportMetadata {
isExportAll?: boolean
namedImportSpecifiers?: string[]
}

Expand Down Expand Up @@ -105,7 +104,6 @@ async function ssrTransformScript(
// Reduce metadata to undefined if it's all default values
if (
metadata &&
metadata.isExportAll !== true &&
(metadata.namedImportSpecifiers == null ||
metadata.namedImportSpecifiers.length === 0)
) {
Expand Down Expand Up @@ -237,9 +235,7 @@ async function ssrTransformScript(
// export * from './foo'
if (node.type === 'ExportAllDeclaration') {
s.remove(node.start, node.end)
const importId = defineImport(node.source.value as string, {
isExportAll: true,
})
const importId = defineImport(node.source.value as string)
// hoist re-exports near the defined import so they are immediately exported
if (node.exported) {
defineExport(hoistIndex, node.exported.name, `${importId}`)
Expand Down

0 comments on commit c5f2d60

Please sign in to comment.