@@ -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
7273// constants
7374const DEFAULT_VAR = `__default__`
@@ -299,6 +300,7 @@ export function compileScript(
299300 let hasDefaultExportName = false
300301 let hasDefaultExportRender = false
301302 let hasDefineOptionsCall = false
303+ let hasDefineSlotsCall = false
302304 let propsRuntimeDecl : Node | undefined
303305 let propsRuntimeDefaults : ObjectExpression | undefined
304306 let propsDestructureDecl : Node | undefined
@@ -593,6 +595,26 @@ export function compileScript(
593595 return true
594596 }
595597
598+ function processDefineSlots ( node : Node , declId ?: LVal ) : boolean {
599+ if ( ! isCallOf ( node , DEFINT_SLOTS ) ) {
600+ return false
601+ }
602+ if ( hasDefineSlotsCall ) {
603+ error ( `duplicate ${ DEFINT_SLOTS } () call` , node )
604+ }
605+ hasDefineSlotsCall = true
606+
607+ if ( declId ) {
608+ s . overwrite (
609+ startOffset + node . start ! ,
610+ startOffset + node . end ! ,
611+ `${ helper ( 'useSlots' ) } ()`
612+ )
613+ }
614+
615+ return true
616+ }
617+
596618 function getAstBody ( ) : Statement [ ] {
597619 return scriptAst
598620 ? [ ...scriptSetupAst . body , ...scriptAst . body ]
@@ -1288,7 +1310,8 @@ export function compileScript(
12881310 processDefineProps ( expr ) ||
12891311 processDefineEmits ( expr ) ||
12901312 processDefineOptions ( expr ) ||
1291- processWithDefaults ( expr )
1313+ processWithDefaults ( expr ) ||
1314+ processDefineSlots ( expr )
12921315 ) {
12931316 s . remove ( node . start ! + startOffset , node . end ! + startOffset )
12941317 } else if ( processDefineExpose ( expr ) ) {
@@ -1323,6 +1346,8 @@ export function compileScript(
13231346 processDefineProps ( init , decl . id ) ||
13241347 processWithDefaults ( init , decl . id , node . kind )
13251348 const isDefineEmits = processDefineEmits ( init , decl . id )
1349+ processDefineSlots ( init , decl . id )
1350+
13261351 if ( isDefineProps || isDefineEmits ) {
13271352 if ( left === 1 ) {
13281353 s . remove ( node . start ! + startOffset , node . end ! + startOffset )
0 commit comments