@@ -68,6 +68,7 @@ const DEFINE_EMITS = 'defineEmits'
68
68
const DEFINE_EXPOSE = 'defineExpose'
69
69
const WITH_DEFAULTS = 'withDefaults'
70
70
const DEFINE_OPTIONS = 'defineOptions'
71
+ const DEFINT_SLOTS = 'defineSlots'
71
72
72
73
const isBuiltInDir = makeMap (
73
74
`once,memo,if,for,else,else-if,slot,text,html,on,bind,model,show,cloak,is`
@@ -313,6 +314,7 @@ export function compileScript(
313
314
let hasDefaultExportName = false
314
315
let hasDefaultExportRender = false
315
316
let hasDefineOptionsCall = false
317
+ let hasDefineSlotsCall = false
316
318
let propsRuntimeDecl : Node | undefined
317
319
let propsRuntimeDefaults : ObjectExpression | undefined
318
320
let propsDestructureDecl : Node | undefined
@@ -607,6 +609,26 @@ export function compileScript(
607
609
return true
608
610
}
609
611
612
+ function processDefineSlots ( node : Node , declId ?: LVal ) : boolean {
613
+ if ( ! isCallOf ( node , DEFINT_SLOTS ) ) {
614
+ return false
615
+ }
616
+ if ( hasDefineSlotsCall ) {
617
+ error ( `duplicate ${ DEFINT_SLOTS } () call` , node )
618
+ }
619
+ hasDefineSlotsCall = true
620
+
621
+ if ( declId ) {
622
+ s . overwrite (
623
+ startOffset + node . start ! ,
624
+ startOffset + node . end ! ,
625
+ `${ helper ( 'useSlots' ) } ()`
626
+ )
627
+ }
628
+
629
+ return true
630
+ }
631
+
610
632
function getAstBody ( ) : Statement [ ] {
611
633
return scriptAst
612
634
? [ ...scriptSetupAst . body , ...scriptAst . body ]
@@ -1302,7 +1324,8 @@ export function compileScript(
1302
1324
processDefineProps ( expr ) ||
1303
1325
processDefineEmits ( expr ) ||
1304
1326
processDefineOptions ( expr ) ||
1305
- processWithDefaults ( expr )
1327
+ processWithDefaults ( expr ) ||
1328
+ processDefineSlots ( expr )
1306
1329
) {
1307
1330
s . remove ( node . start ! + startOffset , node . end ! + startOffset )
1308
1331
} else if ( processDefineExpose ( expr ) ) {
@@ -1337,6 +1360,8 @@ export function compileScript(
1337
1360
processDefineProps ( init , decl . id ) ||
1338
1361
processWithDefaults ( init , decl . id , node . kind )
1339
1362
const isDefineEmits = processDefineEmits ( init , decl . id )
1363
+ processDefineSlots ( init , decl . id )
1364
+
1340
1365
if ( isDefineProps || isDefineEmits ) {
1341
1366
if ( left === 1 ) {
1342
1367
s . remove ( node . start ! + startOffset , node . end ! + startOffset )
0 commit comments