Skip to content

Commit

Permalink
fix(scan): fix top level await handling in script setup
Browse files Browse the repository at this point in the history
close #2044
  • Loading branch information
yyx990803 committed Feb 16, 2021
1 parent 4fd61ab commit 24ed098
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/vite/src/node/optimizer/scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,6 @@ function esbuildScanPlugin(
js += content + '\n'
}
}
if (!js.includes(`export default`)) {
js += `export default {}`
}

if (js.includes('import.meta.glob')) {
return transformGlob(js, path, config.root, loader).then(
Expand All @@ -207,6 +204,16 @@ function esbuildScanPlugin(
)
}

// <script setup> may contain TLA which is not true TLA but esbuild
// will error on it, so replace it with another operator.
if (js.includes('await')) {
js = js.replace(/\bawait\b/g, 'void')
}

if (!js.includes(`export default`)) {
js += `export default {}`
}

return {
loader,
contents: js
Expand Down

0 comments on commit 24ed098

Please sign in to comment.