Skip to content

Commit

Permalink
fix(plugin-vue): special handling for class default export in sfc
Browse files Browse the repository at this point in the history
close #1476
  • Loading branch information
yyx990803 committed Jan 29, 2021
1 parent 4813ffa commit 4b8267d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/plugin-vue/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ async function genTemplateCode(
}
}

const exportDefaultClassRE = /export\s+default\s+class\s+([\w$]+)/

async function genScriptCode(
descriptor: SFCDescriptor,
options: ResolvedOptions,
Expand All @@ -226,7 +228,14 @@ async function genScriptCode(
(!script.lang || (script.lang === 'ts' && options.devServer)) &&
!script.src
) {
scriptCode = rewriteDefault(script.content, `_sfc_main`)
const classMatch = script.content.match(exportDefaultClassRE)
if (classMatch) {
scriptCode =
script.content.replace(exportDefaultClassRE, `class $1`) +
`\nconst _sfc_main = ${classMatch[1]}`
} else {
scriptCode = rewriteDefault(script.content, `_sfc_main`)
}
map = script.map
if (script.lang === 'ts') {
const result = await options.devServer!.transformWithEsbuild(
Expand Down

0 comments on commit 4b8267d

Please sign in to comment.