export const n = 1"
`;
+exports[`SFC compile <script setup> <script> and <script setup> co-usage spaces in ExportDefaultDeclaration node with many spaces and newline 1`] = `
+"import { x } from './x'
+
+ export const n = 1
+ const __default__ = {
+ some:'option'
+ }
+
+function setup(__props, { expose }) {
+
+ x()
+
+return { x }
+}
+
+
+export default /*#__PURE__*/ Object.assign(__default__, {
+ setup
+})"
+`;
+
+exports[`SFC compile <script setup> <script> and <script setup> co-usage spaces in ExportDefaultDeclaration node with minimal spaces 1`] = `
+"import { x } from './x'
+
+ export const n = 1
+ const __default__ = {
+ some:'option'
+ }
+
+function setup(__props, { expose }) {
+
+ x()
+
+return { x }
+}
+
+
+export default /*#__PURE__*/ Object.assign(__default__, {
+ setup
+})"
+`;
+
exports[`SFC compile <script setup> defineEmits() 1`] = `
"export default {
emits: ['foo', 'bar'],
})
describe('<script> and <script setup> co-usage', () => {
+ describe('spaces in ExportDefaultDeclaration node', () => {
+ // #4371
+ test('with many spaces and newline', () => {
+ // #4371
+ const { content } = compile(`
+ <script>
+ export const n = 1
+ export default
+ {
+ some:'option'
+ }
+ </script>
+ <script setup>
+ import { x } from './x'
+ x()
+ </script>
+ `)
+ assertCode(content)
+ })
+
+ test('with minimal spaces', () => {
+ const { content } = compile(`
+ <script>
+ export const n = 1
+ export default{
+ some:'option'
+ }
+ </script>
+ <script setup>
+ import { x } from './x'
+ x()
+ </script>
+ `)
+ assertCode(content)
+ })
+ })
+
test('script first', () => {
const { content } = compile(`
<script>
// export default
defaultExport = node
const start = node.start! + scriptStartOffset!
- s.overwrite(
- start,
- start + `export default`.length,
- `const ${defaultTempVar} =`
- )
+ const end = node.declaration.start! + scriptStartOffset!
+ s.overwrite(start, end, `const ${defaultTempVar} = `)
} else if (node.type === 'ExportNamedDeclaration' && node.specifiers) {
const defaultSpecifier = node.specifiers.find(
s => s.exported.type === 'Identifier' && s.exported.name === 'default'