fix(sfc-playground): Transform named default exports without altering scope (#4154)

Co-authored-by: webfansplz <>
This commit is contained in:
webfansplz 2021-07-20 22:28:02 +08:00 committed by GitHub
parent 457c9aed1f
commit acb2a4d285
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -140,8 +140,18 @@ function processFile(file: File, seen = new Set<File>()) {
// default export
if (node.type === 'ExportDefaultDeclaration') {
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'
if (node.type === 'ExportAllDeclaration') {