From f6991948f59e36bc5d108e2befa5883be99f934f Mon Sep 17 00:00:00 2001 From: Senao <48955231+XiSenao@users.noreply.github.com> Date: Fri, 8 Mar 2024 21:29:55 +0800 Subject: [PATCH] fix: handle function property extension in namespace import (#16113) --- packages/vite/src/node/__tests__/plugins/import.spec.ts | 2 +- packages/vite/src/node/plugins/importAnalysis.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/node/__tests__/plugins/import.spec.ts b/packages/vite/src/node/__tests__/plugins/import.spec.ts index 764b1ab3d187b0..fb9ae3b132325c 100644 --- a/packages/vite/src/node/__tests__/plugins/import.spec.ts +++ b/packages/vite/src/node/__tests__/plugins/import.spec.ts @@ -74,7 +74,7 @@ describe('transformCjsImport', () => { ), ).toBe( 'import __vite__cjsImport0_react from "./node_modules/.vite/deps/react.js"; ' + - `const react = ((m) => m?.__esModule ? m : { ...typeof m === "object" && !Array.isArray(m) ? m : {}, default: m })(__vite__cjsImport0_react)`, + `const react = ((m) => m?.__esModule ? m : { ...typeof m === "object" && !Array.isArray(m) || typeof m === "function" ? m : {}, default: m })(__vite__cjsImport0_react)`, ) }) diff --git a/packages/vite/src/node/plugins/importAnalysis.ts b/packages/vite/src/node/plugins/importAnalysis.ts index e5e3608f7c723c..6b28636cc66bed 100644 --- a/packages/vite/src/node/plugins/importAnalysis.ts +++ b/packages/vite/src/node/plugins/importAnalysis.ts @@ -842,7 +842,7 @@ export function createParseErrorInfo( } } // prettier-ignore -const interopHelper = (m: any) => m?.__esModule ? m : { ...(typeof m === 'object' && !Array.isArray(m) ? m : {}), default: m } +const interopHelper = (m: any) => m?.__esModule ? m : { ...(typeof m === 'object' && !Array.isArray(m) || typeof m === 'function' ? m : {}), default: m } export function interopNamedImports( str: MagicString,