@@ -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
@@ -607,6 +609,26 @@ export function compileScript(
607609 return true
608610 }
609611
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+
610632 function getAstBody ( ) : Statement [ ] {
611633 return scriptAst
612634 ? [ ...scriptSetupAst . body , ...scriptAst . body ]
@@ -1302,7 +1324,8 @@ export function compileScript(
13021324 processDefineProps ( expr ) ||
13031325 processDefineEmits ( expr ) ||
13041326 processDefineOptions ( expr ) ||
1305- processWithDefaults ( expr )
1327+ processWithDefaults ( expr ) ||
1328+ processDefineSlots ( expr )
13061329 ) {
13071330 s . remove ( node . start ! + startOffset , node . end ! + startOffset )
13081331 } else if ( processDefineExpose ( expr ) ) {
@@ -1337,6 +1360,8 @@ export function compileScript(
13371360 processDefineProps ( init , decl . id ) ||
13381361 processWithDefaults ( init , decl . id , node . kind )
13391362 const isDefineEmits = processDefineEmits ( init , decl . id )
1363+ processDefineSlots ( init , decl . id )
1364+
13401365 if ( isDefineProps || isDefineEmits ) {
13411366 if ( left === 1 ) {
13421367 s . remove ( node . start ! + startOffset , node . end ! + startOffset )
0 commit comments