Skip to content

Commit

Permalink
fix: adjust esm syntax judgment logic
Browse files Browse the repository at this point in the history
  • Loading branch information
XiSenao committed Apr 17, 2024
1 parent 6cccef7 commit 5ae8e68
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions packages/vite/src/node/optimizer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const jsExtensionRE = /\.js$/i
const jsMapExtensionRE = /\.js\.map$/i

export type ExportsData = {
hasImports: boolean
hasModuleSyntax: boolean
// exported names (for `export { a as b }`, `b` is exported name)
exports: readonly string[]
// hint if the dep requires loading as jsx
Expand Down Expand Up @@ -1079,9 +1079,9 @@ export async function extractExportsData(
write: false,
format: 'esm',
})
const [imports, exports] = parse(result.outputFiles[0].text)
const [, exports, , hasModuleSyntax] = parse(result.outputFiles[0].text)
return {
hasImports: imports.length > 0,
hasModuleSyntax,
exports: exports.map((e) => e.n),
}
}
Expand All @@ -1104,9 +1104,9 @@ export async function extractExportsData(
usedJsxLoader = true
}

const [imports, exports] = parseResult
const [, exports, , hasModuleSyntax] = parseResult
const exportsData: ExportsData = {
hasImports: imports.length > 0,
hasModuleSyntax,
exports: exports.map((e) => e.n),
jsxLoader: usedJsxLoader,
}
Expand All @@ -1123,9 +1123,9 @@ function needsInterop(
if (getDepOptimizationConfig(config, ssr)?.needsInterop?.includes(id)) {
return true
}
const { hasImports, exports } = exportsData
const { hasModuleSyntax, exports } = exportsData
// entry has no ESM syntax - likely CJS or UMD
if (!exports.length && !hasImports) {
if (!hasModuleSyntax) {
return true
}

Expand Down

0 comments on commit 5ae8e68

Please sign in to comment.