-
-
Notifications
You must be signed in to change notification settings - Fork 371
/
elementDirectives.ts
92 lines (88 loc) · 2.42 KB
/
elementDirectives.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import * as CompilerDOM from '@vue/compiler-dom';
import { camelize } from '@vue/shared';
import type { Code } from '../../types';
import { hyphenateAttr } from '../../utils/shared';
import { endOfLine, wrapWith } from '../common';
import { generateCamelized } from './camelized';
import type { TemplateCodegenContext } from './context';
import type { TemplateCodegenOptions } from './index';
import { generateInterpolation } from './interpolation';
export function* generateElementDirectives(
options: TemplateCodegenOptions,
ctx: TemplateCodegenContext,
node: CompilerDOM.ElementNode,
): Generator<Code> {
for (const prop of node.props) {
if (
prop.type === CompilerDOM.NodeTypes.DIRECTIVE
&& prop.name !== 'slot'
&& prop.name !== 'on'
&& prop.name !== 'model'
&& prop.name !== 'bind'
&& prop.name !== 'scope'
&& prop.name !== 'data'
) {
ctx.accessExternalVariable(camelize('v-' + prop.name), prop.loc.start.offset);
if (prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && !prop.arg.isStatic) {
yield* generateInterpolation(
options,
ctx,
prop.arg.content,
prop.arg.loc,
prop.arg.loc.start.offset + prop.arg.loc.source.indexOf(prop.arg.content),
ctx.codeFeatures.all,
'(',
')',
);
yield endOfLine;
}
yield* wrapWith(
prop.loc.start.offset,
prop.loc.end.offset,
ctx.codeFeatures.verification,
`__VLS_directiveFunction(__VLS_ctx.`,
...generateCamelized(
'v-' + prop.name,
prop.loc.start.offset,
{
...ctx.codeFeatures.all,
verification: false,
completion: {
// fix https://github.com/vuejs/language-tools/issues/1905
isAdditional: true,
},
navigation: {
resolveRenameNewName: camelize,
resolveRenameEditText: getPropRenameApply(prop.name),
},
}
),
`)(`,
...(
prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
? wrapWith(
prop.exp.loc.start.offset,
prop.exp.loc.end.offset,
ctx.codeFeatures.verification,
...generateInterpolation(
options,
ctx,
prop.exp.content,
prop.exp.loc,
prop.exp.loc.start.offset,
ctx.codeFeatures.all,
'(',
')',
),
)
: [`undefined`]
),
`)`,
);
yield endOfLine;
}
}
}
function getPropRenameApply(oldName: string) {
return oldName === hyphenateAttr(oldName) ? hyphenateAttr : undefined;
}