Skip to content

Commit af72eab

Browse files
authored
fix: adjust esm syntax judgment logic (#16436)
1 parent b872635 commit af72eab

File tree

1 file changed

+7
-7
lines changed
  • packages/vite/src/node/optimizer

1 file changed

+7
-7
lines changed

packages/vite/src/node/optimizer/index.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const jsExtensionRE = /\.js$/i
4343
const jsMapExtensionRE = /\.js\.map$/i
4444

4545
export type ExportsData = {
46-
hasImports: boolean
46+
hasModuleSyntax: boolean
4747
// exported names (for `export { a as b }`, `b` is exported name)
4848
exports: readonly string[]
4949
// hint if the dep requires loading as jsx
@@ -1079,9 +1079,9 @@ export async function extractExportsData(
10791079
write: false,
10801080
format: 'esm',
10811081
})
1082-
const [imports, exports] = parse(result.outputFiles[0].text)
1082+
const [, exports, , hasModuleSyntax] = parse(result.outputFiles[0].text)
10831083
return {
1084-
hasImports: imports.length > 0,
1084+
hasModuleSyntax,
10851085
exports: exports.map((e) => e.n),
10861086
}
10871087
}
@@ -1104,9 +1104,9 @@ export async function extractExportsData(
11041104
usedJsxLoader = true
11051105
}
11061106

1107-
const [imports, exports] = parseResult
1107+
const [, exports, , hasModuleSyntax] = parseResult
11081108
const exportsData: ExportsData = {
1109-
hasImports: imports.length > 0,
1109+
hasModuleSyntax,
11101110
exports: exports.map((e) => e.n),
11111111
jsxLoader: usedJsxLoader,
11121112
}
@@ -1123,9 +1123,9 @@ function needsInterop(
11231123
if (getDepOptimizationConfig(config, ssr)?.needsInterop?.includes(id)) {
11241124
return true
11251125
}
1126-
const { hasImports, exports } = exportsData
1126+
const { hasModuleSyntax, exports } = exportsData
11271127
// entry has no ESM syntax - likely CJS or UMD
1128-
if (!exports.length && !hasImports) {
1128+
if (!hasModuleSyntax) {
11291129
return true
11301130
}
11311131

0 commit comments

Comments
 (0)