@@ -69,32 +69,56 @@ describe('sfc props transform', () => {
69
69
} )
70
70
} )
71
71
72
- test ( 'default values w/ runtime declaration' , ( ) => {
72
+ test ( 'default values w/ array runtime declaration' , ( ) => {
73
73
const { content } = compile ( `
74
74
<script setup>
75
- const { foo = 1, bar = {} } = defineProps(['foo', 'bar'])
75
+ const { foo = 1, bar = {}, func = () => {} } = defineProps(['foo', 'bar', 'baz '])
76
76
</script>
77
77
` )
78
78
// literals can be used as-is, non-literals are always returned from a
79
79
// function
80
- expect ( content ) . toMatch ( `props: _mergeDefaults(['foo', 'bar'], {
80
+ // functions need to be marked with a skip marker
81
+ expect ( content ) . toMatch ( `props: _mergeDefaults(['foo', 'bar', 'baz'], {
81
82
foo: 1,
82
- bar: () => ({})
83
+ bar: () => ({}),
84
+ func: () => {}, __skip_func: true
85
+ })` )
86
+ assertCode ( content )
87
+ } )
88
+
89
+ test ( 'default values w/ object runtime declaration' , ( ) => {
90
+ const { content } = compile ( `
91
+ <script setup>
92
+ const { foo = 1, bar = {}, func = () => {}, ext = x } = defineProps({ foo: Number, bar: Object, func: Function, ext: null })
93
+ </script>
94
+ ` )
95
+ // literals can be used as-is, non-literals are always returned from a
96
+ // function
97
+ // functions need to be marked with a skip marker since we cannot always
98
+ // safely infer whether runtime type is Function (e.g. if the runtime decl
99
+ // is imported, or spreads another object)
100
+ expect ( content )
101
+ . toMatch ( `props: _mergeDefaults({ foo: Number, bar: Object, func: Function, ext: null }, {
102
+ foo: 1,
103
+ bar: () => ({}),
104
+ func: () => {}, __skip_func: true,
105
+ ext: x, __skip_ext: true
83
106
})` )
84
107
assertCode ( content )
85
108
} )
86
109
87
110
test ( 'default values w/ type declaration' , ( ) => {
88
111
const { content } = compile ( `
89
112
<script setup lang="ts">
90
- const { foo = 1, bar = {} } = defineProps<{ foo?: number, bar?: object }>()
113
+ const { foo = 1, bar = {}, func = () => {} } = defineProps<{ foo?: number, bar?: object, func?: () => any }>()
91
114
</script>
92
115
` )
93
116
// literals can be used as-is, non-literals are always returned from a
94
117
// function
95
118
expect ( content ) . toMatch ( `props: {
96
119
foo: { type: Number, required: false, default: 1 },
97
- bar: { type: Object, required: false, default: () => ({}) }
120
+ bar: { type: Object, required: false, default: () => ({}) },
121
+ func: { type: Function, required: false, default: () => {} }
98
122
}` )
99
123
assertCode ( content )
100
124
} )
@@ -116,7 +140,7 @@ describe('sfc props transform', () => {
116
140
baz: null,
117
141
boola: { type: Boolean },
118
142
boolb: { type: [Boolean, Number] },
119
- func: { type: Function, default: () => (() => {}) }
143
+ func: { type: Function, default: () => {} }
120
144
}` )
121
145
assertCode ( content )
122
146
} )
0 commit comments