@@ -68,6 +68,7 @@ const DEFINE_EMITS = 'defineEmits'
68
68
const DEFINE_EXPOSE = 'defineExpose'
69
69
const WITH_DEFAULTS = 'withDefaults'
70
70
const DEFINE_OPTIONS = 'defineOptions'
71
+ const DEFINT_SLOTS = 'defineSlots'
71
72
72
73
// constants
73
74
const DEFAULT_VAR = `__default__`
@@ -299,6 +300,7 @@ export function compileScript(
299
300
let hasDefaultExportName = false
300
301
let hasDefaultExportRender = false
301
302
let hasDefineOptionsCall = false
303
+ let hasDefineSlotsCall = false
302
304
let propsRuntimeDecl : Node | undefined
303
305
let propsRuntimeDefaults : ObjectExpression | undefined
304
306
let propsDestructureDecl : Node | undefined
@@ -593,6 +595,26 @@ export function compileScript(
593
595
return true
594
596
}
595
597
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
+
596
618
function getAstBody ( ) : Statement [ ] {
597
619
return scriptAst
598
620
? [ ...scriptSetupAst . body , ...scriptAst . body ]
@@ -1288,7 +1310,8 @@ export function compileScript(
1288
1310
processDefineProps ( expr ) ||
1289
1311
processDefineEmits ( expr ) ||
1290
1312
processDefineOptions ( expr ) ||
1291
- processWithDefaults ( expr )
1313
+ processWithDefaults ( expr ) ||
1314
+ processDefineSlots ( expr )
1292
1315
) {
1293
1316
s . remove ( node . start ! + startOffset , node . end ! + startOffset )
1294
1317
} else if ( processDefineExpose ( expr ) ) {
@@ -1323,6 +1346,8 @@ export function compileScript(
1323
1346
processDefineProps ( init , decl . id ) ||
1324
1347
processWithDefaults ( init , decl . id , node . kind )
1325
1348
const isDefineEmits = processDefineEmits ( init , decl . id )
1349
+ processDefineSlots ( init , decl . id )
1350
+
1326
1351
if ( isDefineProps || isDefineEmits ) {
1327
1352
if ( left === 1 ) {
1328
1353
s . remove ( node . start ! + startOffset , node . end ! + startOffset )
0 commit comments