@@ -18,6 +18,7 @@ const DEFINE_PROPS = 'defineProps'
18
18
const DEFINE_EMITS = 'defineEmits'
19
19
const DEFINE_EXPOSE = 'defineExpose'
20
20
const WITH_DEFAULTS = 'withDefaults'
21
+ const DEFINE_SLOTS = 'defineSlots'
21
22
22
23
export interface PropTypeData {
23
24
key : string
@@ -28,6 +29,7 @@ export interface PropTypeData {
28
29
export function applyMacros ( nodes : Statement [ ] ) {
29
30
let hasDefinePropsCall = false
30
31
let hasDefineEmitCall = false
32
+ let hasDefineSlotsCall = false
31
33
let propsRuntimeDecl : Node | undefined
32
34
let propsRuntimeDefaults : Node | undefined
33
35
let propsTypeDecl : TSTypeLiteral | TSInterfaceBody | undefined
@@ -204,6 +206,23 @@ export function applyMacros(nodes: Statement[]) {
204
206
return true
205
207
}
206
208
209
+ function processDefineSlots (
210
+ node : Node ,
211
+ ) : boolean {
212
+ if ( ! isCallOf ( node , DEFINE_SLOTS ) )
213
+ return false
214
+
215
+ if ( hasDefineSlotsCall )
216
+ error ( `duplicate ${ DEFINE_SLOTS } () call` , node )
217
+
218
+ hasDefineSlotsCall = true
219
+
220
+ if ( node . arguments . length > 0 )
221
+ error ( `${ DEFINE_SLOTS } () cannot accept arguments` , node )
222
+
223
+ return true
224
+ }
225
+
207
226
function genRuntimeProps ( props : Record < string , PropTypeData > ) {
208
227
const keys = Object . keys ( props )
209
228
if ( ! keys . length )
@@ -270,7 +289,9 @@ export function applyMacros(nodes: Statement[]) {
270
289
const decl = node . declarations [ i ]
271
290
if ( decl . init ) {
272
291
if ( processDefineEmits ( decl . init ) )
273
- decl . init = t . memberExpression ( t . identifier ( '__ctx' ) , t . identifier ( 'emit' ) ) as any
292
+ decl . init = t . memberExpression ( t . identifier ( '__ctx' ) , t . identifier ( 'emit' ) )
293
+ else if ( processDefineSlots ( decl . init ) )
294
+ decl . init = t . memberExpression ( t . identifier ( '__ctx' ) , t . identifier ( 'slots' ) )
274
295
else if ( processDefineProps ( decl . init ) || processWithDefaults ( decl . init ) )
275
296
decl . init = t . identifier ( '__props' ) as any
276
297
else
@@ -279,7 +300,7 @@ export function applyMacros(nodes: Statement[]) {
279
300
}
280
301
}
281
302
282
- if ( processWithDefaults ( node ) || processDefineEmits ( node ) || processDefineProps ( node ) || processDefineExpose ( node ) )
303
+ if ( processWithDefaults ( node ) || processDefineEmits ( node ) || processDefineProps ( node ) || processDefineExpose ( node ) || processDefineSlots ( node ) )
283
304
return null
284
305
285
306
throwIfAwait ( node )
0 commit comments