Skip to content

Commit

Permalink
fix: avoid scan failures in .svelte and .astro files (#5193)
Browse files Browse the repository at this point in the history
Co-authored-by: Bjorn Lu <34116392+bluwy@users.noreply.github.com>
  • Loading branch information
benmccann and bluwy committed Oct 11, 2021
1 parent 04b163c commit 386ca79
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/vite/src/node/optimizer/scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,15 @@ function esbuildScanPlugin(
}
}

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

if (code.includes('import.meta.glob')) {
if (js.includes('import.meta.glob')) {
return {
// transformGlob already transforms to js
loader: 'js',
Expand Down

0 comments on commit 386ca79

Please sign in to comment.