File tree 3 files changed +81
-5
lines changed
3 files changed +81
-5
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,48 @@ return { x }
33
33
export const n = 1"
34
34
`;
35
35
36
+ exports[`SFC compile <script setup > <script > and <script setup > co-usage spaces in ExportDefaultDeclaration node with many spaces and newline 1`] = `
37
+ "import { x } from './x'
38
+
39
+ export const n = 1
40
+ const __default__ = {
41
+ some :' option'
42
+ }
43
+
44
+ function setup(__props, { expose } ) {
45
+
46
+ x ()
47
+
48
+ return { x }
49
+ }
50
+
51
+
52
+ export default /*#__PURE__*/ Object.assign(__default__, {
53
+ setup
54
+ } )"
55
+ `;
56
+
57
+ exports[`SFC compile <script setup > <script > and <script setup > co-usage spaces in ExportDefaultDeclaration node with minimal spaces 1`] = `
58
+ "import { x } from './x'
59
+
60
+ export const n = 1
61
+ const __default__ = {
62
+ some :' option'
63
+ }
64
+
65
+ function setup(__props, { expose } ) {
66
+
67
+ x ()
68
+
69
+ return { x }
70
+ }
71
+
72
+
73
+ export default /*#__PURE__*/ Object.assign(__default__, {
74
+ setup
75
+ } )"
76
+ `;
77
+
36
78
exports[`SFC compile <script setup > defineEmits() 1`] = `
37
79
"export default {
38
80
emits : [' foo' , ' bar' ],
Original file line number Diff line number Diff line change @@ -140,6 +140,43 @@ defineExpose({ foo: 123 })
140
140
} )
141
141
142
142
describe ( '<script> and <script setup> co-usage' , ( ) => {
143
+ describe ( 'spaces in ExportDefaultDeclaration node' , ( ) => {
144
+ // #4371
145
+ test ( 'with many spaces and newline' , ( ) => {
146
+ // #4371
147
+ const { content } = compile ( `
148
+ <script>
149
+ export const n = 1
150
+ export default
151
+ {
152
+ some:'option'
153
+ }
154
+ </script>
155
+ <script setup>
156
+ import { x } from './x'
157
+ x()
158
+ </script>
159
+ ` )
160
+ assertCode ( content )
161
+ } )
162
+
163
+ test ( 'with minimal spaces' , ( ) => {
164
+ const { content } = compile ( `
165
+ <script>
166
+ export const n = 1
167
+ export default{
168
+ some:'option'
169
+ }
170
+ </script>
171
+ <script setup>
172
+ import { x } from './x'
173
+ x()
174
+ </script>
175
+ ` )
176
+ assertCode ( content )
177
+ } )
178
+ } )
179
+
143
180
test ( 'script first' , ( ) => {
144
181
const { content } = compile ( `
145
182
<script>
Original file line number Diff line number Diff line change @@ -605,11 +605,8 @@ export function compileScript(
605
605
// export default
606
606
defaultExport = node
607
607
const start = node . start ! + scriptStartOffset !
608
- s . overwrite (
609
- start ,
610
- start + `export default` . length ,
611
- `const ${ defaultTempVar } =`
612
- )
608
+ const end = node . declaration . start ! + scriptStartOffset !
609
+ s . overwrite ( start , end , `const ${ defaultTempVar } = ` )
613
610
} else if ( node . type === 'ExportNamedDeclaration' && node . specifiers ) {
614
611
const defaultSpecifier = node . specifiers . find (
615
612
s => s . exported . type === 'Identifier' && s . exported . name === 'default'
You can’t perform that action at this time.
0 commit comments