@@ -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 DEFINE_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,30 @@ export function compileScript(
590
592
return true
591
593
}
592
594
595
+ function processDefineSlots ( node : Node , declId ?: LVal ) : boolean {
596
+ if ( ! isCallOf ( node , DEFINE_SLOTS ) ) {
597
+ return false
598
+ }
599
+ if ( hasDefineSlotsCall ) {
600
+ error ( `duplicate ${ DEFINE_SLOTS } () call` , node )
601
+ }
602
+ hasDefineSlotsCall = true
603
+
604
+ if ( node . arguments . length > 0 ) {
605
+ error ( `${ DEFINE_SLOTS } () cannot accept arguments` , node )
606
+ }
607
+
608
+ if ( declId ) {
609
+ s . overwrite (
610
+ startOffset + node . start ! ,
611
+ startOffset + node . end ! ,
612
+ `${ helper ( 'useSlots' ) } ()`
613
+ )
614
+ }
615
+
616
+ return true
617
+ }
618
+
593
619
function getAstBody ( ) : Statement [ ] {
594
620
return scriptAst
595
621
? [ ...scriptSetupAst . body , ...scriptAst . body ]
@@ -683,6 +709,7 @@ export function compileScript(
683
709
let propsOption = undefined
684
710
let emitsOption = undefined
685
711
let exposeOption = undefined
712
+ let slotsOption = undefined
686
713
if ( optionsRuntimeDecl . type === 'ObjectExpression' ) {
687
714
for ( const prop of optionsRuntimeDecl . properties ) {
688
715
if (
@@ -692,6 +719,7 @@ export function compileScript(
692
719
if ( prop . key . name === 'props' ) propsOption = prop
693
720
if ( prop . key . name === 'emits' ) emitsOption = prop
694
721
if ( prop . key . name === 'expose' ) exposeOption = prop
722
+ if ( prop . key . name === 'slots' ) slotsOption = prop
695
723
}
696
724
}
697
725
}
@@ -714,6 +742,12 @@ export function compileScript(
714
742
exposeOption
715
743
)
716
744
}
745
+ if ( slotsOption ) {
746
+ error (
747
+ `${ DEFINE_OPTIONS } () cannot be used to declare slots. Use ${ DEFINE_SLOTS } () instead.` ,
748
+ slotsOption
749
+ )
750
+ }
717
751
718
752
return true
719
753
}
@@ -1286,7 +1320,8 @@ export function compileScript(
1286
1320
processDefineProps ( expr ) ||
1287
1321
processDefineEmits ( expr ) ||
1288
1322
processDefineOptions ( expr ) ||
1289
- processWithDefaults ( expr )
1323
+ processWithDefaults ( expr ) ||
1324
+ processDefineSlots ( expr )
1290
1325
) {
1291
1326
s . remove ( node . start ! + startOffset , node . end ! + startOffset )
1292
1327
} else if ( processDefineExpose ( expr ) ) {
@@ -1320,7 +1355,10 @@ export function compileScript(
1320
1355
const isDefineProps =
1321
1356
processDefineProps ( init , decl . id ) ||
1322
1357
processWithDefaults ( init , decl . id )
1323
- const isDefineEmits = processDefineEmits ( init , decl . id )
1358
+ const isDefineEmits =
1359
+ ! isDefineProps && processDefineEmits ( init , decl . id )
1360
+ ! isDefineEmits && processDefineSlots ( init , decl . id )
1361
+
1324
1362
if ( isDefineProps || isDefineEmits ) {
1325
1363
if ( left === 1 ) {
1326
1364
s . remove ( node . start ! + startOffset , node . end ! + startOffset )
0 commit comments