Skip to content

Commit d60e58c

Browse files
authored
fix(compiler-sfc): fix edge case of default export call with no args (#7536)
closes #7534
1 parent 336a3d7 commit d60e58c

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap

+18
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,24 @@ return { n, get x() { return x } }
5959
}"
6060
`;
6161

62+
exports[`SFC compile <script setup> > <script> and <script setup> co-usage > export call expression as default 1`] = `
63+
"function fn() {
64+
return \\"hello, world\\";
65+
}
66+
const __default__ = fn();
67+
68+
export default /*#__PURE__*/Object.assign(__default__, {
69+
setup(__props, { expose }) {
70+
expose();
71+
72+
console.log('foo')
73+
74+
return { fn }
75+
}
76+
77+
})"
78+
`;
79+
6280
exports[`SFC compile <script setup> > <script> and <script setup> co-usage > script first 1`] = `
6381
"import { x } from './x'
6482

packages/compiler-sfc/__tests__/compileScript.spec.ts

+16
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,22 @@ defineExpose({ foo: 123 })
386386
assertCode(content)
387387
})
388388
})
389+
390+
test('export call expression as default', () => {
391+
const { content } = compile(`
392+
<script>
393+
function fn() {
394+
return "hello, world";
395+
}
396+
export default fn();
397+
</script>
398+
399+
<script setup>
400+
console.log('foo')
401+
</script>
402+
`)
403+
assertCode(content)
404+
})
389405
})
390406

391407
describe('imports', () => {

packages/compiler-sfc/src/compileScript.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,7 @@ export function compileScript(
11161116
optionProperties = defaultExport.declaration.properties
11171117
} else if (
11181118
defaultExport.declaration.type === 'CallExpression' &&
1119+
defaultExport.declaration.arguments[0] &&
11191120
defaultExport.declaration.arguments[0].type === 'ObjectExpression'
11201121
) {
11211122
optionProperties = defaultExport.declaration.arguments[0].properties

0 commit comments

Comments
 (0)