1
1
import * as CompilerDOM from '@vue/compiler-dom' ;
2
2
import { camelize , capitalize } from '@vue/shared' ;
3
3
import type * as ts from 'typescript' ;
4
- import type { Code } from '../../types' ;
4
+ import type { Code , VueCodeInformation } from '../../types' ;
5
5
import { combineLastMapping , createTsAst , endOfLine , identifierRegex , newLine } from '../utils' ;
6
6
import { generateCamelized } from '../utils/camelized' ;
7
7
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 { generateObjectProperty } from './objectProperty' ;
12
11
13
12
export function * generateElementEvents (
14
13
options : TemplateCodegenOptions ,
@@ -40,6 +39,7 @@ export function* generateElementEvents(
40
39
yield `let ${ emitsVar } !: __VLS_ResolveEmits<typeof ${ componentOriginalVar } , typeof ${ componentCtxVar } .emit>${ endOfLine } ` ;
41
40
yield `let ${ propsVar } !: __VLS_FunctionalComponentProps<typeof ${ componentFunctionalVar } , typeof ${ componentVNodeVar } >${ endOfLine } ` ;
42
41
}
42
+
43
43
let source = prop . arg ?. loc . source ?? 'model-value' ;
44
44
let start = prop . arg ?. loc . start . offset ;
45
45
let propPrefix = 'on-' ;
@@ -54,18 +54,14 @@ export function* generateElementEvents(
54
54
propPrefix = 'onVnode-' ;
55
55
emitPrefix = 'vnode-' ;
56
56
}
57
- yield `(): __VLS_NormalizeComponentEvent<typeof ${ propsVar } , typeof ${ emitsVar } , '${ camelize ( propPrefix + source ) } ', '${ emitPrefix + source } ', '${ camelize ( emitPrefix + source ) } '> => (${ newLine } ` ;
57
+ const propName = camelize ( propPrefix + source ) ;
58
+ const emitName = emitPrefix + source ;
59
+ const camelizedEmitName = camelize ( emitName ) ;
60
+
61
+ yield `(): __VLS_NormalizeComponentEvent<typeof ${ propsVar } , typeof ${ emitsVar } , '${ propName } ', '${ emitName } ', '${ camelizedEmitName } '> => (${ newLine } ` ;
58
62
if ( prop . name === 'on' ) {
59
63
yield `{ ` ;
60
- yield * generateObjectProperty (
61
- options ,
62
- ctx ,
63
- emitPrefix + source ,
64
- start ! ,
65
- ctx . codeFeatures . navigation ,
66
- undefined ,
67
- true
68
- ) ;
64
+ yield * generateEventArg ( ctx , source , start ! , emitPrefix . slice ( 0 , - 1 ) , ctx . codeFeatures . navigation ) ;
69
65
yield `: {} as any } as typeof ${ emitsVar } ,${ newLine } ` ;
70
66
}
71
67
yield `{ ` ;
@@ -75,7 +71,7 @@ export function* generateElementEvents(
75
71
yield * generateEventExpression ( options , ctx , prop ) ;
76
72
}
77
73
else {
78
- yield `'${ camelize ( propPrefix + source ) } ': ` ;
74
+ yield `'${ propName } ': ` ;
79
75
yield * generateModelEventExpression ( options , ctx , prop ) ;
80
76
}
81
77
yield `})${ endOfLine } ` ;
@@ -87,21 +83,19 @@ export function* generateEventArg(
87
83
ctx : TemplateCodegenContext ,
88
84
name : string ,
89
85
start : number ,
90
- directive = 'on'
91
- ) : Generator < Code > {
92
- const features = {
86
+ directive = 'on' ,
87
+ features : VueCodeInformation = {
93
88
...ctx . codeFeatures . withoutHighlightAndCompletion ,
94
89
...ctx . codeFeatures . navigationWithoutRename ,
95
- } ;
90
+ }
91
+ ) : Generator < Code > {
92
+ if ( directive . length ) {
93
+ name = capitalize ( name ) ;
94
+ }
96
95
if ( identifierRegex . test ( camelize ( name ) ) ) {
97
96
yield [ '' , 'template' , start , features ] ;
98
97
yield directive ;
99
- yield * generateCamelized (
100
- capitalize ( name ) ,
101
- 'template' ,
102
- start ,
103
- combineLastMapping
104
- ) ;
98
+ yield * generateCamelized ( name , 'template' , start , combineLastMapping ) ;
105
99
}
106
100
else {
107
101
yield * wrapWith (
@@ -110,12 +104,7 @@ export function* generateEventArg(
110
104
features ,
111
105
`'` ,
112
106
directive ,
113
- ...generateCamelized (
114
- capitalize ( name ) ,
115
- 'template' ,
116
- start ,
117
- combineLastMapping
118
- ) ,
107
+ ...generateCamelized ( name , 'template' , start , combineLastMapping ) ,
119
108
`'`
120
109
) ;
121
110
}
0 commit comments