mirror of https://github.com/vuejs/core.git
fix(compiler-sfc): fix edge case of default export call with no args (#7536)
closes #7534
This commit is contained in:
parent
336a3d7b91
commit
d60e58c9f6
|
@ -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'
|
||||||
|
|
||||||
|
|
|
@ -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', () => {
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue