Skip to content

Commit

Permalink
fix(compiler-sfc): fix edge case of default export call with no args (v…
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz authored and IAmSSH committed Apr 29, 2023
1 parent 4ea2d9f commit 2bce58b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
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 @@ -386,6 +386,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 @@ -1116,6 +1116,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

0 comments on commit 2bce58b

Please sign in to comment.