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

fix: special handling for class default export in sfc #29

Merged
merged 1 commit into from
Jan 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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