Skip to content

Commit 386ca79

Browse files
benmccannbluwy
andauthored
fix: avoid scan failures in .svelte and .astro files (#5193)
Co-authored-by: Bjorn Lu <34116392+bluwy@users.noreply.github.com>
1 parent 04b163c commit 386ca79

File tree

1 file changed

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

1 file changed

+7
-3
lines changed

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

+7-3
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,15 @@ function esbuildScanPlugin(
272272
}
273273
}
274274

275-
if (!code.includes(`export default`)) {
276-
js += `\nexport default {}`
275+
// This will trigger incorrectly if `export default` is contained
276+
// anywhere in a string. Svelte and Astro files can't have
277+
// `export default` as code so we know if it's encountered it's a
278+
// false positive (e.g. contained in a string)
279+
if (!path.endsWith('.vue') || !js.includes('export default')) {
280+
js += '\nexport default {}'
277281
}
278282

279-
if (code.includes('import.meta.glob')) {
283+
if (js.includes('import.meta.glob')) {
280284
return {
281285
// transformGlob already transforms to js
282286
loader: 'js',

0 commit comments

Comments
 (0)