@@ -67,6 +67,7 @@ const DEFINE_EMITS = 'defineEmits'
67
67
const DEFINE_EXPOSE = 'defineExpose'
68
68
const WITH_DEFAULTS = 'withDefaults'
69
69
const DEFINE_OPTIONS = 'defineOptions'
70
+ const DEFINT_SLOTS = 'defineSlots'
70
71
71
72
const isBuiltInDir = makeMap (
72
73
`once,memo,if,for,else,else-if,slot,text,html,on,bind,model,show,cloak,is`
@@ -312,6 +313,7 @@ export function compileScript(
312
313
let hasDefaultExportName = false
313
314
let hasDefaultExportRender = false
314
315
let hasDefineOptionsCall = false
316
+ let hasDefineSlotsCall = false
315
317
let propsRuntimeDecl : Node | undefined
316
318
let propsRuntimeDefaults : Node | undefined
317
319
let propsDestructureDecl : Node | undefined
@@ -590,6 +592,26 @@ export function compileScript(
590
592
return true
591
593
}
592
594
595
+ function processDefineSlots ( node : Node , declId ?: LVal ) : boolean {
596
+ if ( ! isCallOf ( node , DEFINT_SLOTS ) ) {
597
+ return false
598
+ }
599
+ if ( hasDefineSlotsCall ) {
600
+ error ( `duplicate ${ DEFINT_SLOTS } () call` , node )
601
+ }
602
+ hasDefineSlotsCall = true
603
+
604
+ if ( declId ) {
605
+ s . overwrite (
606
+ startOffset + node . start ! ,
607
+ startOffset + node . end ! ,
608
+ `${ helper ( 'useSlots' ) } ()`
609
+ )
610
+ }
611
+
612
+ return true
613
+ }
614
+
593
615
function getAstBody ( ) : Statement [ ] {
594
616
return scriptAst
595
617
? [ ...scriptSetupAst . body , ...scriptAst . body ]
@@ -1286,7 +1308,8 @@ export function compileScript(
1286
1308
processDefineProps ( expr ) ||
1287
1309
processDefineEmits ( expr ) ||
1288
1310
processDefineOptions ( expr ) ||
1289
- processWithDefaults ( expr )
1311
+ processWithDefaults ( expr ) ||
1312
+ processDefineSlots ( expr )
1290
1313
) {
1291
1314
s . remove ( node . start ! + startOffset , node . end ! + startOffset )
1292
1315
} else if ( processDefineExpose ( expr ) ) {
@@ -1321,6 +1344,8 @@ export function compileScript(
1321
1344
processDefineProps ( init , decl . id ) ||
1322
1345
processWithDefaults ( init , decl . id )
1323
1346
const isDefineEmits = processDefineEmits ( init , decl . id )
1347
+ processDefineSlots ( init , decl . id )
1348
+
1324
1349
if ( isDefineProps || isDefineEmits ) {
1325
1350
if ( left === 1 ) {
1326
1351
s . remove ( node . start ! + startOffset , node . end ! + startOffset )
0 commit comments