@@ -67,6 +67,7 @@ const DEFINE_EMITS = 'defineEmits'
6767const DEFINE_EXPOSE = 'defineExpose'
6868const WITH_DEFAULTS = 'withDefaults'
6969const DEFINE_OPTIONS = 'defineOptions'
70+ const DEFINT_SLOTS = 'defineSlots'
7071
7172const isBuiltInDir = makeMap (
7273 `once,memo,if,for,else,else-if,slot,text,html,on,bind,model,show,cloak,is`
@@ -312,6 +313,7 @@ export function compileScript(
312313 let hasDefaultExportName = false
313314 let hasDefaultExportRender = false
314315 let hasDefineOptionsCall = false
316+ let hasDefineSlotsCall = false
315317 let propsRuntimeDecl : Node | undefined
316318 let propsRuntimeDefaults : Node | undefined
317319 let propsDestructureDecl : Node | undefined
@@ -590,6 +592,26 @@ export function compileScript(
590592 return true
591593 }
592594
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+
593615 function getAstBody ( ) : Statement [ ] {
594616 return scriptAst
595617 ? [ ...scriptSetupAst . body , ...scriptAst . body ]
@@ -1286,7 +1308,8 @@ export function compileScript(
12861308 processDefineProps ( expr ) ||
12871309 processDefineEmits ( expr ) ||
12881310 processDefineOptions ( expr ) ||
1289- processWithDefaults ( expr )
1311+ processWithDefaults ( expr ) ||
1312+ processDefineSlots ( expr )
12901313 ) {
12911314 s . remove ( node . start ! + startOffset , node . end ! + startOffset )
12921315 } else if ( processDefineExpose ( expr ) ) {
@@ -1321,6 +1344,8 @@ export function compileScript(
13211344 processDefineProps ( init , decl . id ) ||
13221345 processWithDefaults ( init , decl . id )
13231346 const isDefineEmits = processDefineEmits ( init , decl . id )
1347+ processDefineSlots ( init , decl . id )
1348+
13241349 if ( isDefineProps || isDefineEmits ) {
13251350 if ( left === 1 ) {
13261351 s . remove ( node . start ! + startOffset , node . end ! + startOffset )
0 commit comments