Skip to content

Commit acb2a4d

Browse files
authored
fix(sfc-playground): Transform named default exports without altering scope (#4154)
Co-authored-by: webfansplz <>
1 parent 457c9ae commit acb2a4d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

packages/sfc-playground/src/output/moduleCompiler.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,17 @@ function processFile(file: File, seen = new Set<File>()) {
140140

141141
// default export
142142
if (node.type === 'ExportDefaultDeclaration') {
143-
s.overwrite(node.start!, node.start! + 14, `${moduleKey}.default =`)
143+
if ('id' in node.declaration && node.declaration.id) {
144+
// named hoistable/class exports
145+
// export default function foo() {}
146+
// export default class A {}
147+
const { name } = node.declaration.id
148+
s.remove(node.start!, node.start! + 15)
149+
s.append(`\n${exportKey}(${moduleKey}, "default", () => ${name})`)
150+
} else {
151+
// anonymous default exports
152+
s.overwrite(node.start!, node.start! + 14, `${moduleKey}.default =`)
153+
}
144154
}
145155

146156
// export * from './foo'

0 commit comments

Comments
 (0)