Skip to content

Commit

Permalink
fix(sfc-playground): Transform named default exports without altering…
Browse files Browse the repository at this point in the history
… scope (#4154)

Co-authored-by: webfansplz <>
  • Loading branch information
webfansplz committed Jul 20, 2021
1 parent 457c9ae commit acb2a4d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/sfc-playground/src/output/moduleCompiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,17 @@ function processFile(file: File, seen = new Set<File>()) {

// 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'
Expand Down

0 comments on commit acb2a4d

Please sign in to comment.