Skip to content

Commit

Permalink
fix(plugin-vue): handle default rewrite edge case for commented class
Browse files Browse the repository at this point in the history
close #2277
  • Loading branch information
yyx990803 committed Feb 26, 2021
1 parent 167a9c3 commit 2900a9a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/plugin-vue/src/main.ts
Expand Up @@ -219,7 +219,7 @@ async function genTemplateCode(
}
}

const exportDefaultClassRE = /export\s+default\s+class\s+([\w$]+)/
const exportDefaultClassRE = /(?:(?:^|\n|;)\s*)export\s+default\s+class\s+([\w$]+)/

async function genScriptCode(
descriptor: SFCDescriptor,
Expand All @@ -240,11 +240,16 @@ async function genScriptCode(
(!script.lang || (script.lang === 'ts' && options.devServer)) &&
!script.src
) {
// TODO remove the class check logic after upgrading @vue/compiler-sfc
const classMatch = script.content.match(exportDefaultClassRE)
if (classMatch) {
scriptCode =
script.content.replace(exportDefaultClassRE, `class $1`) +
`\nconst _sfc_main = ${classMatch[1]}`
if (/export\s+default/.test(scriptCode)) {
// fallback if there are still export default
scriptCode = rewriteDefault(script.content, `_sfc_main`)
}
} else {
scriptCode = rewriteDefault(script.content, `_sfc_main`)
}
Expand Down

0 comments on commit 2900a9a

Please sign in to comment.