@@ -8,17 +8,18 @@ import { wrapWith } from '../utils/wrapWith';
8
8
import type { TemplateCodegenContext } from './context' ;
9
9
import type { TemplateCodegenOptions } from './index' ;
10
10
import { generateInterpolation } from './interpolation' ;
11
+ import { generatePropertyAccess } from './propertyAccess' ;
11
12
12
13
export function * generateElementEvents (
13
14
options : TemplateCodegenOptions ,
14
15
ctx : TemplateCodegenContext ,
15
16
node : CompilerDOM . ElementNode ,
17
+ componentOriginalVar : string ,
16
18
componentFunctionalVar : string ,
17
19
componentVNodeVar : string ,
18
20
componentCtxVar : string
19
21
) : Generator < Code > {
20
- let emitVar : string | undefined ;
21
- let eventsVar : string | undefined ;
22
+ let emitsVar : string | undefined ;
22
23
let propsVar : string | undefined ;
23
24
24
25
for ( const prop of node . props ) {
@@ -33,12 +34,10 @@ export function* generateElementEvents(
33
34
)
34
35
) {
35
36
ctx . currentComponent ! . used = true ;
36
- if ( ! emitVar ) {
37
- emitVar = ctx . getInternalVariable ( ) ;
38
- eventsVar = ctx . getInternalVariable ( ) ;
37
+ if ( ! emitsVar ) {
38
+ emitsVar = ctx . getInternalVariable ( ) ;
39
39
propsVar = ctx . getInternalVariable ( ) ;
40
- yield `let ${ emitVar } !: typeof ${ componentCtxVar } .emit${ endOfLine } ` ;
41
- yield `let ${ eventsVar } !: __VLS_NormalizeEmits<typeof ${ emitVar } >${ endOfLine } ` ;
40
+ yield `let ${ emitsVar } !: __VLS_ResolveEmits<typeof ${ componentOriginalVar } , typeof ${ componentCtxVar } .emit>${ endOfLine } ` ;
42
41
yield `let ${ propsVar } !: __VLS_FunctionalComponentProps<typeof ${ componentFunctionalVar } , typeof ${ componentVNodeVar } >${ endOfLine } ` ;
43
42
}
44
43
let source = prop . arg ?. loc . source ?? 'model-value' ;
@@ -55,7 +54,16 @@ export function* generateElementEvents(
55
54
propPrefix = 'onVnode-' ;
56
55
emitPrefix = 'vnode-' ;
57
56
}
58
- yield `(): __VLS_NormalizeComponentEvent<typeof ${ propsVar } , typeof ${ eventsVar } , '${ camelize ( propPrefix + source ) } ', '${ emitPrefix + source } ', '${ camelize ( emitPrefix + source ) } '> => ({${ newLine } ` ;
57
+ yield `(): __VLS_NormalizeComponentEvent<typeof ${ propsVar } , typeof ${ emitsVar } , '${ camelize ( propPrefix + source ) } ', '${ emitPrefix + source } ', '${ camelize ( emitPrefix + source ) } '> => (` ;
58
+ yield emitsVar ;
59
+ yield * generatePropertyAccess (
60
+ options ,
61
+ ctx ,
62
+ emitPrefix + source ,
63
+ start ,
64
+ ctx . codeFeatures . navigation
65
+ ) ;
66
+ yield `, {${ newLine } ` ;
59
67
if ( prop . name === 'on' ) {
60
68
yield * generateEventArg ( ctx , source , start ! , propPrefix . slice ( 0 , - 1 ) ) ;
61
69
yield `: ` ;
0 commit comments