Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.

Commit

Permalink
fix: special handling for class default export in sfc (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
Djaler authored Jan 30, 2021
1 parent 70c6387 commit 3be490d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ function injectStyles (context) {
return result
}

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

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

0 comments on commit 3be490d

Please sign in to comment.