@@ -68,6 +68,7 @@ const DEFINE_EMITS = 'defineEmits'
6868const DEFINE_EXPOSE = 'defineExpose'
6969const WITH_DEFAULTS = 'withDefaults'
7070const DEFINE_OPTIONS = 'defineOptions'
71+ const DEFINT_SLOTS = 'defineSlots'
7172
7273const isBuiltInDir = makeMap (
7374 `once,memo,if,for,else,else-if,slot,text,html,on,bind,model,show,cloak,is`
@@ -313,6 +314,7 @@ export function compileScript(
313314 let hasDefaultExportName = false
314315 let hasDefaultExportRender = false
315316 let hasDefineOptionsCall = false
317+ let hasDefineSlotsCall = false
316318 let propsRuntimeDecl : Node | undefined
317319 let propsRuntimeDefaults : ObjectExpression | undefined
318320 let propsDestructureDecl : Node | undefined
@@ -606,6 +608,26 @@ export function compileScript(
606608 return true
607609 }
608610
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+
609631 function getAstBody ( ) : Statement [ ] {
610632 return scriptAst
611633 ? [ ...scriptSetupAst . body , ...scriptAst . body ]
@@ -1301,7 +1323,8 @@ export function compileScript(
13011323 processDefineProps ( expr ) ||
13021324 processDefineEmits ( expr ) ||
13031325 processDefineOptions ( expr ) ||
1304- processWithDefaults ( expr )
1326+ processWithDefaults ( expr ) ||
1327+ processDefineSlots ( expr )
13051328 ) {
13061329 s . remove ( node . start ! + startOffset , node . end ! + startOffset )
13071330 } else if ( processDefineExpose ( expr ) ) {
@@ -1336,6 +1359,8 @@ export function compileScript(
13361359 processDefineProps ( init , decl . id ) ||
13371360 processWithDefaults ( init , decl . id , node . kind )
13381361 const isDefineEmits = processDefineEmits ( init , decl . id )
1362+ processDefineSlots ( init , decl . id )
1363+
13391364 if ( isDefineProps || isDefineEmits ) {
13401365 if ( left === 1 ) {
13411366 s . remove ( node . start ! + startOffset , node . end ! + startOffset )
0 commit comments