@@ -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
@@ -606,6 +608,26 @@ export function compileScript(
606
608
return true
607
609
}
608
610
611
+ function processDefineSlots ( node : Node , declId ?: LVal ) : boolean {
612
+ if ( ! isCallOf ( node , DEFINT_SLOTS ) ) {
613
+ return false
614
+ }
615
+ if ( hasDefineSlotsCall ) {
616
+ error ( `duplicate ${ DEFINT_SLOTS } () call` , node )
617
+ }
618
+ hasDefineSlotsCall = true
619
+
620
+ if ( declId ) {
621
+ s . overwrite (
622
+ startOffset + node . start ! ,
623
+ startOffset + node . end ! ,
624
+ `${ helper ( 'useSlots' ) } ()`
625
+ )
626
+ }
627
+
628
+ return true
629
+ }
630
+
609
631
function getAstBody ( ) : Statement [ ] {
610
632
return scriptAst
611
633
? [ ...scriptSetupAst . body , ...scriptAst . body ]
@@ -1301,7 +1323,8 @@ export function compileScript(
1301
1323
processDefineProps ( expr ) ||
1302
1324
processDefineEmits ( expr ) ||
1303
1325
processDefineOptions ( expr ) ||
1304
- processWithDefaults ( expr )
1326
+ processWithDefaults ( expr ) ||
1327
+ processDefineSlots ( expr )
1305
1328
) {
1306
1329
s . remove ( node . start ! + startOffset , node . end ! + startOffset )
1307
1330
} else if ( processDefineExpose ( expr ) ) {
@@ -1336,6 +1359,8 @@ export function compileScript(
1336
1359
processDefineProps ( init , decl . id ) ||
1337
1360
processWithDefaults ( init , decl . id , node . kind )
1338
1361
const isDefineEmits = processDefineEmits ( init , decl . id )
1362
+ processDefineSlots ( init , decl . id )
1363
+
1339
1364
if ( isDefineProps || isDefineEmits ) {
1340
1365
if ( left === 1 ) {
1341
1366
s . remove ( node . start ! + startOffset , node . end ! + startOffset )
0 commit comments