From: webfansplz <308241863@qq.com> Date: Tue, 20 Jul 2021 14:28:02 +0000 (+0800) Subject: fix(sfc-playground): Transform named default exports without altering scope (#4154) X-Git-Tag: v3.2.0-beta.3~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=acb2a4d285bfdee6437970b3dc9435abfe1c4ddf;p=thirdparty%2Fvuejs%2Fcore.git fix(sfc-playground): Transform named default exports without altering scope (#4154) Co-authored-by: webfansplz <> --- diff --git a/packages/sfc-playground/src/output/moduleCompiler.ts b/packages/sfc-playground/src/output/moduleCompiler.ts index dbb82a52f4..8906289737 100644 --- a/packages/sfc-playground/src/output/moduleCompiler.ts +++ b/packages/sfc-playground/src/output/moduleCompiler.ts @@ -140,7 +140,17 @@ function processFile(file: File, seen = new Set()) { // default export if (node.type === 'ExportDefaultDeclaration') { - s.overwrite(node.start!, node.start! + 14, `${moduleKey}.default =`) + if ('id' in node.declaration && node.declaration.id) { + // named hoistable/class exports + // export default function foo() {} + // export default class A {} + const { name } = node.declaration.id + s.remove(node.start!, node.start! + 15) + s.append(`\n${exportKey}(${moduleKey}, "default", () => ${name})`) + } else { + // anonymous default exports + s.overwrite(node.start!, node.start! + 14, `${moduleKey}.default =`) + } } // export * from './foo'