Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compiler-sfc): export call expression as default #7536

Merged
merged 2 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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`] = `
"import { x } from './x'

Expand Down
16 changes: 16 additions & 0 deletions packages/compiler-sfc/__tests__/compileScript.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,22 @@ defineExpose({ foo: 123 })
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', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/compiler-sfc/src/compileScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,7 @@ export function compileScript(
optionProperties = defaultExport.declaration.properties
} else if (
defaultExport.declaration.type === 'CallExpression' &&
defaultExport.declaration.arguments[0] &&
defaultExport.declaration.arguments[0].type === 'ObjectExpression'
) {
optionProperties = defaultExport.declaration.arguments[0].properties
Expand Down