fix(compiler-sfc): fix edge case of default export call with no args (#7536)

closes #7534
This commit is contained in:
三咲智子 Kevin Deng 2023-03-28 16:27:34 +08:00 committed by GitHub
parent 336a3d7b91
commit d60e58c9f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 0 deletions

View File

@ -59,6 +59,24 @@ return { n, get x() { return x } }
}" }"
`; `;
exports[`SFC compile <script setup> > <script> and <script setup> co-usage > export call expression as default 1`] = `
"function fn() {
return \\"hello, world\\";
}
const __default__ = fn();
export default /*#__PURE__*/Object.assign(__default__, {
setup(__props, { expose }) {
expose();
console.log('foo')
return { fn }
}
})"
`;
exports[`SFC compile <script setup> > <script> and <script setup> co-usage > script first 1`] = ` exports[`SFC compile <script setup> > <script> and <script setup> co-usage > script first 1`] = `
"import { x } from './x' "import { x } from './x'

View File

@ -386,6 +386,22 @@ defineExpose({ foo: 123 })
assertCode(content) assertCode(content)
}) })
}) })
test('export call expression as default', () => {
const { content } = compile(`
<script>
function fn() {
return "hello, world";
}
export default fn();
</script>
<script setup>
console.log('foo')
</script>
`)
assertCode(content)
})
}) })
describe('imports', () => { describe('imports', () => {

View File

@ -1116,6 +1116,7 @@ export function compileScript(
optionProperties = defaultExport.declaration.properties optionProperties = defaultExport.declaration.properties
} else if ( } else if (
defaultExport.declaration.type === 'CallExpression' && defaultExport.declaration.type === 'CallExpression' &&
defaultExport.declaration.arguments[0] &&
defaultExport.declaration.arguments[0].type === 'ObjectExpression' defaultExport.declaration.arguments[0].type === 'ObjectExpression'
) { ) {
optionProperties = defaultExport.declaration.arguments[0].properties optionProperties = defaultExport.declaration.arguments[0].properties