@@ -4,9 +4,10 @@ import { createVBindShorthandInlayHintInfo } from '../inlayHints';
4
4
import { endOfLine , newLine , wrapWith } from '../utils' ;
5
5
import type { TemplateCodegenContext } from './context' ;
6
6
import { generateElementChildren } from './elementChildren' ;
7
- import { generateElementProps } from './elementProps' ;
7
+ import { generateElementProps , generatePropExp } from './elementProps' ;
8
8
import type { TemplateCodegenOptions } from './index' ;
9
9
import { generateInterpolation } from './interpolation' ;
10
+ import { generatePropertyAccess } from './propertyAccess' ;
10
11
11
12
export function * generateSlotOutlet (
12
13
options : TemplateCodegenOptions ,
@@ -30,23 +31,56 @@ export function* generateSlotOutlet(
30
31
31
32
if ( options . hasDefineSlots ) {
32
33
yield `__VLS_normalizeSlot(` ;
33
- yield * wrapWith (
34
- node . loc . start . offset ,
35
- node . loc . end . offset ,
36
- ctx . codeFeatures . verification ,
37
- `${ options . slotsAssignName ?? '__VLS_slots' } [` ,
38
- ...wrapWith (
34
+ if ( nameProp ) {
35
+ let codes : Generator < Code > | Code [ ] ;
36
+ if ( nameProp . type === CompilerDOM . NodeTypes . ATTRIBUTE && nameProp . value ) {
37
+ let { source, start : { offset } } = nameProp . value . loc ;
38
+ if ( source . startsWith ( '"' ) || source . startsWith ( "'" ) ) {
39
+ source = source . slice ( 1 , - 1 ) ;
40
+ offset ++ ;
41
+ }
42
+ codes = generatePropertyAccess (
43
+ options ,
44
+ ctx ,
45
+ source ,
46
+ offset ,
47
+ ctx . codeFeatures . navigationAndVerification
48
+ ) ;
49
+ }
50
+ else if ( nameProp . type === CompilerDOM . NodeTypes . DIRECTIVE && nameProp . exp ?. type === CompilerDOM . NodeTypes . SIMPLE_EXPRESSION ) {
51
+ codes = [
52
+ `[` ,
53
+ ...generatePropExp (
54
+ options ,
55
+ ctx ,
56
+ nameProp ,
57
+ nameProp . exp ,
58
+ ctx . codeFeatures . all ,
59
+ true
60
+ ) ,
61
+ `]`
62
+ ] ;
63
+ }
64
+ else {
65
+ codes = [ `['default']` ] ;
66
+ }
67
+
68
+ yield * wrapWith (
69
+ nameProp . loc . start . offset ,
70
+ nameProp . loc . end . offset ,
71
+ ctx . codeFeatures . verification ,
72
+ `${ options . slotsAssignName ?? '__VLS_slots' } ` ,
73
+ ...codes
74
+ ) ;
75
+ }
76
+ else {
77
+ yield * wrapWith (
39
78
node . loc . start . offset ,
40
79
node . loc . end . offset ,
41
80
ctx . codeFeatures . verification ,
42
- nameProp ?. type === CompilerDOM . NodeTypes . ATTRIBUTE && nameProp . value
43
- ? `'${ nameProp . value . content } '`
44
- : nameProp ?. type === CompilerDOM . NodeTypes . DIRECTIVE && nameProp . exp ?. type === CompilerDOM . NodeTypes . SIMPLE_EXPRESSION
45
- ? nameProp . exp . content
46
- : `('default' as const)`
47
- ) ,
48
- `]`
49
- ) ;
81
+ `${ options . slotsAssignName ?? '__VLS_slots' } ['default']`
82
+ ) ;
83
+ }
50
84
yield `)?.(` ;
51
85
yield * wrapWith (
52
86
startTagOffset ,
0 commit comments