diff --git a/packages/vinext/src/index.ts b/packages/vinext/src/index.ts index 49fab906..3d669a8f 100644 --- a/packages/vinext/src/index.ts +++ b/packages/vinext/src/index.ts @@ -3790,8 +3790,9 @@ function stripServerExports(code: string): string | null { continue; } - // Case 3: export { getServerSideProps } or export { getServerSideProps as gSSP } - if (node.specifiers && node.specifiers.length > 0 && !node.source) { + // Case 3: export { getServerSideProps }, export { getServerSideProps as gSSP }, + // or export { getServerSideProps } from "./server" + if (node.specifiers && node.specifiers.length > 0) { const kept: any[] = []; const stripped: string[] = []; for (const spec of node.specifiers) { @@ -3812,7 +3813,8 @@ function stripServerExports(code: string): string | null { const exported = sp.exported?.name ?? sp.exported?.value; return local === exported ? local : `${local} as ${exported}`; }).join(", "); - parts.push(`export { ${keptStr} };`); + const source = node.source ? ` from ${code.slice(node.source.start, node.source.end)}` : ""; + parts.push(`export { ${keptStr} }${source};`); } for (const name of stripped) { parts.push(`export const ${name} = undefined;`); diff --git a/tests/build-optimization.test.ts b/tests/build-optimization.test.ts index fd627e0e..ac958ec0 100644 --- a/tests/build-optimization.test.ts +++ b/tests/build-optimization.test.ts @@ -1244,6 +1244,35 @@ export { getServerSideProps, config }; expect(result).toContain("export const getServerSideProps = undefined;"); }); + + it("handles export-from re-exports", () => { + const code = ` +export default function Page() { + return null; +} + +export { getServerSideProps } from './server'; +`; + const result = _stripServerExports(code); + expect(result).not.toBeNull(); + expect(result).toContain("export const getServerSideProps = undefined;"); + expect(result).not.toContain("from './server'"); + }); + + it("handles export-from with mixed specifiers", () => { + const code = ` +export default function Page() { + return null; +} + +export { getServerSideProps, config } from './server'; +`; + const result = _stripServerExports(code); + expect(result).not.toBeNull(); + expect(result).toContain("export { config } from './server';"); + expect(result).toContain("export const getServerSideProps = undefined;"); + }); + it("handles strings containing braces", () => { const code = ` export default function Page({ msg }) {