@vue/language-core 2.0.13 → 2.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/lib/codegen/common.d.ts +11 -0
- package/lib/codegen/common.js +70 -0
- package/lib/codegen/script/component.d.ts +9 -0
- package/lib/codegen/script/component.js +109 -0
- package/lib/codegen/script/context.d.ts +25 -0
- package/lib/codegen/script/context.js +124 -0
- package/lib/{generators → codegen/script}/globalTypes.d.ts +1 -1
- package/lib/codegen/script/globalTypes.js +135 -0
- package/lib/codegen/script/index.d.ts +33 -0
- package/lib/codegen/script/index.js +127 -0
- package/lib/codegen/script/internalComponent.d.ts +5 -0
- package/lib/codegen/script/internalComponent.js +58 -0
- package/lib/codegen/script/scriptSetup.d.ts +6 -0
- package/lib/codegen/script/scriptSetup.js +371 -0
- package/lib/codegen/script/src.d.ts +2 -0
- package/lib/codegen/script/src.js +52 -0
- package/lib/codegen/script/template.d.ts +5 -0
- package/lib/codegen/script/template.js +196 -0
- package/lib/codegen/template/camelized.d.ts +2 -0
- package/lib/codegen/template/camelized.js +32 -0
- package/lib/codegen/template/context.d.ts +44 -0
- package/lib/codegen/template/context.js +170 -0
- package/lib/codegen/template/element.d.ts +8 -0
- package/lib/codegen/template/element.js +378 -0
- package/lib/codegen/template/elementChildren.d.ts +5 -0
- package/lib/codegen/template/elementChildren.js +26 -0
- package/lib/codegen/template/elementDirectives.d.ts +5 -0
- package/lib/codegen/template/elementDirectives.js +46 -0
- package/lib/codegen/template/elementEvents.d.ts +9 -0
- package/lib/codegen/template/elementEvents.js +157 -0
- package/lib/codegen/template/elementProps.d.ts +5 -0
- package/lib/codegen/template/elementProps.js +275 -0
- package/lib/codegen/template/index.d.ts +60 -0
- package/lib/codegen/template/index.js +130 -0
- package/lib/codegen/template/interpolation.d.ts +6 -0
- package/lib/{utils/transform.js → codegen/template/interpolation.js} +76 -46
- package/lib/codegen/template/objectProperty.d.ts +4 -0
- package/lib/codegen/template/objectProperty.js +31 -0
- package/lib/codegen/template/propertyAccess.d.ts +4 -0
- package/lib/codegen/template/propertyAccess.js +24 -0
- package/lib/codegen/template/slotOutlet.d.ts +5 -0
- package/lib/codegen/template/slotOutlet.js +72 -0
- package/lib/codegen/template/stringLiteralKey.d.ts +2 -0
- package/lib/codegen/template/stringLiteralKey.js +14 -0
- package/lib/codegen/template/templateChild.d.ts +7 -0
- package/lib/codegen/template/templateChild.js +160 -0
- package/lib/codegen/template/vFor.d.ts +12 -0
- package/lib/codegen/template/vFor.js +69 -0
- package/lib/codegen/template/vIf.d.ts +5 -0
- package/lib/codegen/template/vIf.js +53 -0
- package/lib/languageModule.d.ts +3 -4
- package/lib/languageModule.js +31 -14
- package/lib/parsers/scriptSetupRanges.d.ts +1 -0
- package/lib/parsers/scriptSetupRanges.js +6 -1
- package/lib/plugins/file-html.js +63 -66
- package/lib/plugins/file-md.js +47 -50
- package/lib/plugins/shared.d.ts +2 -0
- package/lib/plugins/shared.js +12 -0
- package/lib/plugins/vue-sfc-customblocks.js +2 -2
- package/lib/plugins/vue-sfc-scripts.js +2 -3
- package/lib/plugins/vue-sfc-styles.js +3 -3
- package/lib/plugins/vue-sfc-template.js +2 -2
- package/lib/plugins/vue-template-inline-css.js +34 -2
- package/lib/plugins/vue-template-inline-ts.js +10 -8
- package/lib/plugins/vue-tsx.d.ts +43 -5
- package/lib/plugins/vue-tsx.js +38 -28
- package/lib/plugins.d.ts +2 -1
- package/lib/plugins.js +18 -9
- package/lib/types.d.ts +3 -3
- package/lib/utils/ts.js +20 -32
- package/lib/virtualFile/computedFiles.d.ts +2 -1
- package/lib/virtualFile/computedFiles.js +41 -15
- package/lib/virtualFile/computedMappings.js +3 -3
- package/lib/virtualFile/computedSfc.js +22 -1
- package/lib/virtualFile/embeddedFile.d.ts +2 -3
- package/lib/virtualFile/embeddedFile.js +1 -2
- package/lib/virtualFile/vueFile.d.ts +3 -5
- package/lib/virtualFile/vueFile.js +6 -8
- package/package.json +3 -3
- package/lib/generators/globalTypes.js +0 -135
- package/lib/generators/inlineCss.d.ts +0 -3
- package/lib/generators/inlineCss.js +0 -37
- package/lib/generators/script.d.ts +0 -13
- package/lib/generators/script.js +0 -981
- package/lib/generators/template.d.ts +0 -19
- package/lib/generators/template.js +0 -1578
- package/lib/generators/utils.d.ts +0 -5
- package/lib/generators/utils.js +0 -54
- package/lib/utils/transform.d.ts +0 -8
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPossibleOriginalComponentNames = exports.getCanonicalComponentName = exports.generateElement = exports.generateComponent = void 0;
|
|
4
|
+
const CompilerDOM = require("@vue/compiler-dom");
|
|
5
|
+
const shared_1 = require("@vue/shared");
|
|
6
|
+
const shared_2 = require("../../utils/shared");
|
|
7
|
+
const common_1 = require("../common");
|
|
8
|
+
const camelized_1 = require("./camelized");
|
|
9
|
+
const elementChildren_1 = require("./elementChildren");
|
|
10
|
+
const elementDirectives_1 = require("./elementDirectives");
|
|
11
|
+
const elementEvents_1 = require("./elementEvents");
|
|
12
|
+
const elementProps_1 = require("./elementProps");
|
|
13
|
+
const interpolation_1 = require("./interpolation");
|
|
14
|
+
const propertyAccess_1 = require("./propertyAccess");
|
|
15
|
+
const templateChild_1 = require("./templateChild");
|
|
16
|
+
const colonReg = /:/g;
|
|
17
|
+
function* generateComponent(options, ctx, node, currentComponent, componentCtxVar) {
|
|
18
|
+
const startTagOffset = node.loc.start.offset + options.template.content.substring(node.loc.start.offset).indexOf(node.tag);
|
|
19
|
+
const propsFailedExps = [];
|
|
20
|
+
const var_originalComponent = ctx.getInternalVariable();
|
|
21
|
+
const var_functionalComponent = ctx.getInternalVariable();
|
|
22
|
+
const var_componentInstance = ctx.getInternalVariable();
|
|
23
|
+
const var_componentEvents = ctx.getInternalVariable();
|
|
24
|
+
const isComponentTag = node.tag.toLowerCase() === 'component';
|
|
25
|
+
let endTagOffset = !node.isSelfClosing && options.template.lang === 'html' ? node.loc.start.offset + node.loc.source.lastIndexOf(node.tag) : undefined;
|
|
26
|
+
let tag = node.tag;
|
|
27
|
+
let tagOffsets = endTagOffset !== undefined
|
|
28
|
+
? [startTagOffset, endTagOffset]
|
|
29
|
+
: [startTagOffset];
|
|
30
|
+
let props = node.props;
|
|
31
|
+
let dynamicTagInfo;
|
|
32
|
+
let defineComponentCtxVar;
|
|
33
|
+
let usedComponentEventsVar = false;
|
|
34
|
+
if (isComponentTag) {
|
|
35
|
+
for (const prop of node.props) {
|
|
36
|
+
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE && prop.name === 'bind' && prop.arg?.loc.source === 'is' && prop.exp) {
|
|
37
|
+
dynamicTagInfo = {
|
|
38
|
+
exp: prop.exp.loc.source,
|
|
39
|
+
offset: prop.exp.loc.start.offset,
|
|
40
|
+
astHolder: prop.exp.loc,
|
|
41
|
+
};
|
|
42
|
+
props = props.filter(p => p !== prop);
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else if (tag.includes('.')) {
|
|
48
|
+
// namespace tag
|
|
49
|
+
dynamicTagInfo = {
|
|
50
|
+
exp: tag,
|
|
51
|
+
astHolder: node.loc,
|
|
52
|
+
offset: startTagOffset,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
if (dynamicTagInfo) {
|
|
56
|
+
yield `const ${var_originalComponent} = `;
|
|
57
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, dynamicTagInfo.exp, dynamicTagInfo.astHolder, dynamicTagInfo.offset, ctx.codeFeatures.all, '(', ')');
|
|
58
|
+
yield common_1.endOfLine;
|
|
59
|
+
}
|
|
60
|
+
else if (!isComponentTag) {
|
|
61
|
+
yield `const ${var_originalComponent} = ({} as `;
|
|
62
|
+
for (const componentName of getPossibleOriginalComponentNames(tag, true)) {
|
|
63
|
+
yield `'${componentName}' extends keyof typeof __VLS_ctx ? { '${getCanonicalComponentName(tag)}': typeof __VLS_ctx`;
|
|
64
|
+
yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, componentName);
|
|
65
|
+
yield ` }: `;
|
|
66
|
+
}
|
|
67
|
+
yield `typeof __VLS_resolvedLocalAndGlobalComponents)`;
|
|
68
|
+
yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, getCanonicalComponentName(tag), startTagOffset, ctx.codeFeatures.verification);
|
|
69
|
+
yield common_1.endOfLine;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
yield `const ${var_originalComponent} = {} as any${common_1.endOfLine}`;
|
|
73
|
+
}
|
|
74
|
+
yield `const ${var_functionalComponent} = __VLS_asFunctionalComponent(${var_originalComponent}, new ${var_originalComponent}({`;
|
|
75
|
+
yield* (0, elementProps_1.generateElementProps)(options, ctx, node, props, false);
|
|
76
|
+
yield `}))${common_1.endOfLine}`;
|
|
77
|
+
if (!dynamicTagInfo
|
|
78
|
+
&& !isComponentTag) {
|
|
79
|
+
// hover support
|
|
80
|
+
for (const offset of tagOffsets) {
|
|
81
|
+
yield `({} as { ${getCanonicalComponentName(tag)}: typeof ${var_originalComponent} }).`;
|
|
82
|
+
yield* generateCanonicalComponentName(tag, offset, ctx.codeFeatures.withoutHighlightAndCompletionAndNavigation);
|
|
83
|
+
yield common_1.endOfLine;
|
|
84
|
+
}
|
|
85
|
+
const camelizedTag = (0, shared_1.camelize)(node.tag);
|
|
86
|
+
if (common_1.variableNameRegex.test(camelizedTag)) {
|
|
87
|
+
// renaming / find references support
|
|
88
|
+
for (const tagOffset of tagOffsets) {
|
|
89
|
+
for (const shouldCapitalize of (node.tag[0] === node.tag[0].toUpperCase() ? [false] : [true, false])) {
|
|
90
|
+
const expectName = shouldCapitalize ? (0, shared_1.capitalize)(camelizedTag) : camelizedTag;
|
|
91
|
+
yield `__VLS_components.`;
|
|
92
|
+
yield* (0, camelized_1.generateCamelized)(shouldCapitalize ? (0, shared_1.capitalize)(node.tag) : node.tag, tagOffset, {
|
|
93
|
+
navigation: {
|
|
94
|
+
resolveRenameNewName: node.tag !== expectName ? camelizeComponentName : undefined,
|
|
95
|
+
resolveRenameEditText: getTagRenameApply(node.tag),
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
yield `;`;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
yield `${common_1.newLine}`;
|
|
102
|
+
// auto import support
|
|
103
|
+
yield `// @ts-ignore${common_1.newLine}`; // #2304
|
|
104
|
+
yield `[`;
|
|
105
|
+
for (const tagOffset of tagOffsets) {
|
|
106
|
+
yield* (0, camelized_1.generateCamelized)((0, shared_1.capitalize)(node.tag), tagOffset, {
|
|
107
|
+
completion: {
|
|
108
|
+
isAdditional: true,
|
|
109
|
+
onlyImport: true,
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
yield `,`;
|
|
113
|
+
}
|
|
114
|
+
yield `]${common_1.endOfLine}`;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (options.vueCompilerOptions.strictTemplates) {
|
|
118
|
+
// with strictTemplates, generate once for props type-checking + instance type
|
|
119
|
+
yield `const ${var_componentInstance} = ${var_functionalComponent}(`;
|
|
120
|
+
yield* (0, common_1.wrapWith)(startTagOffset, startTagOffset + tag.length, ctx.codeFeatures.verification, `{`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, props, true, propsFailedExps), `}`);
|
|
121
|
+
yield `, ...__VLS_functionalComponentArgsRest(${var_functionalComponent}))${common_1.endOfLine}`;
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
// without strictTemplates, this only for instacne type
|
|
125
|
+
yield `const ${var_componentInstance} = ${var_functionalComponent}({`;
|
|
126
|
+
yield* (0, elementProps_1.generateElementProps)(options, ctx, node, props, false);
|
|
127
|
+
yield `}, ...__VLS_functionalComponentArgsRest(${var_functionalComponent}))${common_1.endOfLine}`;
|
|
128
|
+
// and this for props type-checking
|
|
129
|
+
yield `({} as (props: __VLS_FunctionalComponentProps<typeof ${var_originalComponent}, typeof ${var_componentInstance}> & Record<string, unknown>) => void)(`;
|
|
130
|
+
yield* (0, common_1.wrapWith)(startTagOffset, startTagOffset + tag.length, ctx.codeFeatures.verification, `{`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, props, true, propsFailedExps), `}`);
|
|
131
|
+
yield `)${common_1.endOfLine}`;
|
|
132
|
+
}
|
|
133
|
+
defineComponentCtxVar = ctx.getInternalVariable();
|
|
134
|
+
componentCtxVar = defineComponentCtxVar;
|
|
135
|
+
currentComponent = node;
|
|
136
|
+
for (const failedExp of propsFailedExps) {
|
|
137
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, failedExp.loc.source, failedExp.loc, failedExp.loc.start.offset, ctx.codeFeatures.all, '(', ')');
|
|
138
|
+
yield common_1.endOfLine;
|
|
139
|
+
}
|
|
140
|
+
yield* generateVScope(options, ctx, node, props);
|
|
141
|
+
if (componentCtxVar) {
|
|
142
|
+
ctx.usedComponentCtxVars.add(componentCtxVar);
|
|
143
|
+
yield* (0, elementEvents_1.generateElementEvents)(options, ctx, node, var_functionalComponent, var_componentInstance, var_componentEvents, () => usedComponentEventsVar = true);
|
|
144
|
+
}
|
|
145
|
+
const slotDir = node.props.find(p => p.type === CompilerDOM.NodeTypes.DIRECTIVE && p.name === 'slot');
|
|
146
|
+
if (slotDir && componentCtxVar) {
|
|
147
|
+
yield* generateComponentSlot(options, ctx, node, slotDir, currentComponent, componentCtxVar);
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node, currentComponent, componentCtxVar);
|
|
151
|
+
}
|
|
152
|
+
if (defineComponentCtxVar && ctx.usedComponentCtxVars.has(defineComponentCtxVar)) {
|
|
153
|
+
yield `const ${componentCtxVar} = __VLS_pickFunctionalComponentCtx(${var_originalComponent}, ${var_componentInstance})!${common_1.endOfLine}`;
|
|
154
|
+
}
|
|
155
|
+
if (usedComponentEventsVar) {
|
|
156
|
+
yield `let ${var_componentEvents}!: __VLS_NormalizeEmits<typeof ${componentCtxVar}.emit>${common_1.endOfLine}`;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
exports.generateComponent = generateComponent;
|
|
160
|
+
function* generateElement(options, ctx, node, currentComponent, componentCtxVar) {
|
|
161
|
+
const startTagOffset = node.loc.start.offset + options.template.content.substring(node.loc.start.offset).indexOf(node.tag);
|
|
162
|
+
const endTagOffset = !node.isSelfClosing && options.template.lang === 'html'
|
|
163
|
+
? node.loc.start.offset + node.loc.source.lastIndexOf(node.tag)
|
|
164
|
+
: undefined;
|
|
165
|
+
const propsFailedExps = [];
|
|
166
|
+
yield `__VLS_elementAsFunction(__VLS_intrinsicElements`;
|
|
167
|
+
yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, startTagOffset, ctx.codeFeatures.withoutHighlightAndCompletion);
|
|
168
|
+
if (endTagOffset !== undefined) {
|
|
169
|
+
yield `, __VLS_intrinsicElements`;
|
|
170
|
+
yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, endTagOffset, ctx.codeFeatures.withoutHighlightAndCompletion);
|
|
171
|
+
}
|
|
172
|
+
yield `)(`;
|
|
173
|
+
yield* (0, common_1.wrapWith)(startTagOffset, startTagOffset + node.tag.length, ctx.codeFeatures.verification, `{`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, node.props, true, propsFailedExps), `}`);
|
|
174
|
+
yield `)${common_1.endOfLine}`;
|
|
175
|
+
for (const failedExp of propsFailedExps) {
|
|
176
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, failedExp.loc.source, failedExp.loc, failedExp.loc.start.offset, ctx.codeFeatures.all, '(', ')');
|
|
177
|
+
yield common_1.endOfLine;
|
|
178
|
+
}
|
|
179
|
+
yield* generateVScope(options, ctx, node, node.props);
|
|
180
|
+
const slotDir = node.props.find(p => p.type === CompilerDOM.NodeTypes.DIRECTIVE && p.name === 'slot');
|
|
181
|
+
if (slotDir && componentCtxVar) {
|
|
182
|
+
yield* generateComponentSlot(options, ctx, node, slotDir, currentComponent, componentCtxVar);
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node, currentComponent, componentCtxVar);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
exports.generateElement = generateElement;
|
|
189
|
+
function* generateVScope(options, ctx, node, props) {
|
|
190
|
+
const vScope = props.find(prop => prop.type === CompilerDOM.NodeTypes.DIRECTIVE && (prop.name === 'scope' || prop.name === 'data'));
|
|
191
|
+
let inScope = false;
|
|
192
|
+
let originalConditionsNum = ctx.blockConditions.length;
|
|
193
|
+
if (vScope?.type === CompilerDOM.NodeTypes.DIRECTIVE && vScope.exp) {
|
|
194
|
+
const scopeVar = ctx.getInternalVariable();
|
|
195
|
+
const condition = `__VLS_withScope(__VLS_ctx, ${scopeVar})`;
|
|
196
|
+
yield `const ${scopeVar} = `;
|
|
197
|
+
yield [
|
|
198
|
+
vScope.exp.loc.source,
|
|
199
|
+
'template',
|
|
200
|
+
vScope.exp.loc.start.offset,
|
|
201
|
+
ctx.codeFeatures.all,
|
|
202
|
+
];
|
|
203
|
+
yield common_1.endOfLine;
|
|
204
|
+
yield `if (${condition}) {${common_1.newLine}`;
|
|
205
|
+
ctx.blockConditions.push(condition);
|
|
206
|
+
inScope = true;
|
|
207
|
+
}
|
|
208
|
+
yield* (0, elementDirectives_1.generateElementDirectives)(options, ctx, node);
|
|
209
|
+
yield* generateReferencesForElements(options, ctx, node); // <el ref="foo" />
|
|
210
|
+
if (options.shouldGenerateScopedClasses) {
|
|
211
|
+
yield* generateReferencesForScopedCssClasses(ctx, node);
|
|
212
|
+
}
|
|
213
|
+
if (inScope) {
|
|
214
|
+
yield `}${common_1.newLine}`;
|
|
215
|
+
ctx.blockConditions.length = originalConditionsNum;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
function getCanonicalComponentName(tagText) {
|
|
219
|
+
return common_1.variableNameRegex.test(tagText)
|
|
220
|
+
? tagText
|
|
221
|
+
: (0, shared_1.capitalize)((0, shared_1.camelize)(tagText.replace(colonReg, '-')));
|
|
222
|
+
}
|
|
223
|
+
exports.getCanonicalComponentName = getCanonicalComponentName;
|
|
224
|
+
function getPossibleOriginalComponentNames(tagText, deduplicate) {
|
|
225
|
+
const name1 = (0, shared_1.capitalize)((0, shared_1.camelize)(tagText));
|
|
226
|
+
const name2 = (0, shared_1.camelize)(tagText);
|
|
227
|
+
const name3 = tagText;
|
|
228
|
+
const names = [name1];
|
|
229
|
+
if (!deduplicate || name2 !== name1) {
|
|
230
|
+
names.push(name2);
|
|
231
|
+
}
|
|
232
|
+
if (!deduplicate || name3 !== name2) {
|
|
233
|
+
names.push(name3);
|
|
234
|
+
}
|
|
235
|
+
return names;
|
|
236
|
+
}
|
|
237
|
+
exports.getPossibleOriginalComponentNames = getPossibleOriginalComponentNames;
|
|
238
|
+
function* generateCanonicalComponentName(tagText, offset, features) {
|
|
239
|
+
if (common_1.variableNameRegex.test(tagText)) {
|
|
240
|
+
yield [tagText, 'template', offset, features];
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
yield* (0, camelized_1.generateCamelized)((0, shared_1.capitalize)(tagText.replace(colonReg, '-')), offset, features);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
function* generateComponentSlot(options, ctx, node, slotDir, currentComponent, componentCtxVar) {
|
|
247
|
+
yield `{${common_1.newLine}`;
|
|
248
|
+
ctx.usedComponentCtxVars.add(componentCtxVar);
|
|
249
|
+
if (currentComponent) {
|
|
250
|
+
ctx.hasSlotElements.add(currentComponent);
|
|
251
|
+
}
|
|
252
|
+
const slotBlockVars = [];
|
|
253
|
+
let hasProps = false;
|
|
254
|
+
if (slotDir?.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
255
|
+
const slotAst = (0, common_1.createTsAst)(options.ts, slotDir, `(${slotDir.exp.content}) => {}`);
|
|
256
|
+
(0, common_1.collectVars)(options.ts, slotAst, slotAst, slotBlockVars);
|
|
257
|
+
hasProps = true;
|
|
258
|
+
if (!slotDir.exp.content.includes(':')) {
|
|
259
|
+
yield `const [`;
|
|
260
|
+
yield [
|
|
261
|
+
slotDir.exp.content,
|
|
262
|
+
'template',
|
|
263
|
+
slotDir.exp.loc.start.offset,
|
|
264
|
+
ctx.codeFeatures.all,
|
|
265
|
+
];
|
|
266
|
+
yield `] = __VLS_getSlotParams(`;
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
yield `const `;
|
|
270
|
+
yield [
|
|
271
|
+
slotDir.exp.content,
|
|
272
|
+
'template',
|
|
273
|
+
slotDir.exp.loc.start.offset,
|
|
274
|
+
ctx.codeFeatures.all,
|
|
275
|
+
];
|
|
276
|
+
yield ` = __VLS_getSlotParam(`;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
yield* (0, common_1.wrapWith)((slotDir.arg ?? slotDir).loc.start.offset, (slotDir.arg ?? slotDir).loc.end.offset, ctx.codeFeatures.verification, `(${componentCtxVar}.slots!)`, ...(slotDir?.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && slotDir.arg.content
|
|
280
|
+
? (0, propertyAccess_1.generatePropertyAccess)(options, ctx, slotDir.arg.loc.source, slotDir.arg.loc.start.offset, slotDir.arg.isStatic ? ctx.codeFeatures.withoutHighlight : ctx.codeFeatures.all, slotDir.arg.loc)
|
|
281
|
+
: [
|
|
282
|
+
`.`,
|
|
283
|
+
...(0, common_1.wrapWith)(slotDir.loc.start.offset, slotDir.loc.start.offset + (slotDir.loc.source.startsWith('#')
|
|
284
|
+
? '#'.length
|
|
285
|
+
: slotDir.loc.source.startsWith('v-slot:')
|
|
286
|
+
? 'v-slot:'.length
|
|
287
|
+
: 0), ctx.codeFeatures.withoutHighlightAndCompletion, `default`)
|
|
288
|
+
]));
|
|
289
|
+
if (hasProps) {
|
|
290
|
+
yield `)`;
|
|
291
|
+
}
|
|
292
|
+
yield common_1.endOfLine;
|
|
293
|
+
for (const varName of slotBlockVars) {
|
|
294
|
+
ctx.addLocalVariable(varName);
|
|
295
|
+
}
|
|
296
|
+
yield* ctx.resetDirectiveComments('end of slot children start');
|
|
297
|
+
let prev;
|
|
298
|
+
for (const childNode of node.children) {
|
|
299
|
+
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, currentComponent, prev, componentCtxVar);
|
|
300
|
+
prev = childNode;
|
|
301
|
+
}
|
|
302
|
+
for (const varName of slotBlockVars) {
|
|
303
|
+
ctx.removeLocalVariable(varName);
|
|
304
|
+
}
|
|
305
|
+
let isStatic = true;
|
|
306
|
+
if (slotDir?.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
307
|
+
isStatic = slotDir.arg.isStatic;
|
|
308
|
+
}
|
|
309
|
+
if (isStatic && slotDir && !slotDir.arg) {
|
|
310
|
+
yield `${componentCtxVar}.slots!['`;
|
|
311
|
+
yield [
|
|
312
|
+
'',
|
|
313
|
+
'template',
|
|
314
|
+
slotDir.loc.start.offset + (slotDir.loc.source.startsWith('#')
|
|
315
|
+
? '#'.length : slotDir.loc.source.startsWith('v-slot:')
|
|
316
|
+
? 'v-slot:'.length
|
|
317
|
+
: 0),
|
|
318
|
+
ctx.codeFeatures.completion,
|
|
319
|
+
];
|
|
320
|
+
yield `'/* empty slot name completion */]${common_1.newLine}`;
|
|
321
|
+
}
|
|
322
|
+
yield* ctx.generateAutoImportCompletion();
|
|
323
|
+
yield `}${common_1.newLine}`;
|
|
324
|
+
}
|
|
325
|
+
function* generateReferencesForElements(options, ctx, node) {
|
|
326
|
+
for (const prop of node.props) {
|
|
327
|
+
if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE
|
|
328
|
+
&& prop.name === 'ref'
|
|
329
|
+
&& prop.value) {
|
|
330
|
+
yield `// @ts-ignore${common_1.newLine}`;
|
|
331
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, prop.value.content, prop.value.loc, prop.value.loc.start.offset + 1, ctx.codeFeatures.navigation, '(', ')');
|
|
332
|
+
yield common_1.endOfLine;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
function* generateReferencesForScopedCssClasses(ctx, node) {
|
|
337
|
+
for (const prop of node.props) {
|
|
338
|
+
if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE
|
|
339
|
+
&& prop.name === 'class'
|
|
340
|
+
&& prop.value) {
|
|
341
|
+
let startOffset = prop.value.loc.start.offset;
|
|
342
|
+
let tempClassName = '';
|
|
343
|
+
for (const char of (prop.value.loc.source + ' ')) {
|
|
344
|
+
if (char.trim() === '' || char === '"' || char === "'") {
|
|
345
|
+
if (tempClassName !== '') {
|
|
346
|
+
ctx.scopedClasses.push({ className: tempClassName, offset: startOffset });
|
|
347
|
+
startOffset += tempClassName.length;
|
|
348
|
+
tempClassName = '';
|
|
349
|
+
}
|
|
350
|
+
startOffset += char.length;
|
|
351
|
+
}
|
|
352
|
+
else {
|
|
353
|
+
tempClassName += char;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
else if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
358
|
+
&& prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
359
|
+
&& prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
360
|
+
&& prop.arg.content === 'class') {
|
|
361
|
+
yield `__VLS_styleScopedClasses = (`;
|
|
362
|
+
yield [
|
|
363
|
+
prop.exp.content,
|
|
364
|
+
'template',
|
|
365
|
+
prop.exp.loc.start.offset,
|
|
366
|
+
ctx.codeFeatures.navigationAndCompletion,
|
|
367
|
+
];
|
|
368
|
+
yield `)${common_1.endOfLine}`;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
function camelizeComponentName(newName) {
|
|
373
|
+
return (0, shared_1.camelize)('-' + newName);
|
|
374
|
+
}
|
|
375
|
+
function getTagRenameApply(oldName) {
|
|
376
|
+
return oldName === (0, shared_2.hyphenateTag)(oldName) ? shared_2.hyphenateTag : undefined;
|
|
377
|
+
}
|
|
378
|
+
//# sourceMappingURL=element.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import * as CompilerDOM from '@vue/compiler-dom';
|
|
2
|
+
import type { Code } from '../../types';
|
|
3
|
+
import type { TemplateCodegenContext } from './context';
|
|
4
|
+
import type { TemplateCodegenOptions } from './index';
|
|
5
|
+
export declare function generateElementChildren(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, currentComponent: CompilerDOM.ElementNode | undefined, componentCtxVar: string | undefined): Generator<Code>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateElementChildren = void 0;
|
|
4
|
+
const CompilerDOM = require("@vue/compiler-dom");
|
|
5
|
+
const common_1 = require("../common");
|
|
6
|
+
const templateChild_1 = require("./templateChild");
|
|
7
|
+
function* generateElementChildren(options, ctx, node, currentComponent, componentCtxVar) {
|
|
8
|
+
yield* ctx.resetDirectiveComments('end of element children start');
|
|
9
|
+
let prev;
|
|
10
|
+
for (const childNode of node.children) {
|
|
11
|
+
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, currentComponent, prev, componentCtxVar);
|
|
12
|
+
prev = childNode;
|
|
13
|
+
}
|
|
14
|
+
yield* ctx.generateAutoImportCompletion();
|
|
15
|
+
// fix https://github.com/vuejs/language-tools/issues/932
|
|
16
|
+
if (!ctx.hasSlotElements.has(node)
|
|
17
|
+
&& node.children.length
|
|
18
|
+
&& node.tagType !== CompilerDOM.ElementTypes.ELEMENT
|
|
19
|
+
&& node.tagType !== CompilerDOM.ElementTypes.TEMPLATE) {
|
|
20
|
+
yield `(${componentCtxVar}.slots!).`;
|
|
21
|
+
yield* (0, common_1.wrapWith)(node.children[0].loc.start.offset, node.children[node.children.length - 1].loc.end.offset, ctx.codeFeatures.navigation, `default`);
|
|
22
|
+
yield common_1.endOfLine;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.generateElementChildren = generateElementChildren;
|
|
26
|
+
//# sourceMappingURL=elementChildren.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import * as CompilerDOM from '@vue/compiler-dom';
|
|
2
|
+
import type { Code } from '../../types';
|
|
3
|
+
import type { TemplateCodegenContext } from './context';
|
|
4
|
+
import type { TemplateCodegenOptions } from './index';
|
|
5
|
+
export declare function generateElementDirectives(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode): Generator<Code>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateElementDirectives = void 0;
|
|
4
|
+
const CompilerDOM = require("@vue/compiler-dom");
|
|
5
|
+
const shared_1 = require("@vue/shared");
|
|
6
|
+
const shared_2 = require("../../utils/shared");
|
|
7
|
+
const common_1 = require("../common");
|
|
8
|
+
const camelized_1 = require("./camelized");
|
|
9
|
+
const interpolation_1 = require("./interpolation");
|
|
10
|
+
function* generateElementDirectives(options, ctx, node) {
|
|
11
|
+
for (const prop of node.props) {
|
|
12
|
+
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
13
|
+
&& prop.name !== 'slot'
|
|
14
|
+
&& prop.name !== 'on'
|
|
15
|
+
&& prop.name !== 'model'
|
|
16
|
+
&& prop.name !== 'bind'
|
|
17
|
+
&& prop.name !== 'scope'
|
|
18
|
+
&& prop.name !== 'data') {
|
|
19
|
+
ctx.accessGlobalVariable((0, shared_1.camelize)('v-' + prop.name), prop.loc.start.offset);
|
|
20
|
+
if (prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && !prop.arg.isStatic) {
|
|
21
|
+
yield* (0, interpolation_1.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, '(', ')');
|
|
22
|
+
yield common_1.endOfLine;
|
|
23
|
+
}
|
|
24
|
+
yield* (0, common_1.wrapWith)(prop.loc.start.offset, prop.loc.end.offset, ctx.codeFeatures.verification, `__VLS_directiveFunction(__VLS_ctx.`, ...(0, camelized_1.generateCamelized)('v-' + prop.name, prop.loc.start.offset, {
|
|
25
|
+
...ctx.codeFeatures.all,
|
|
26
|
+
verification: false,
|
|
27
|
+
completion: {
|
|
28
|
+
// fix https://github.com/vuejs/language-tools/issues/1905
|
|
29
|
+
isAdditional: true,
|
|
30
|
+
},
|
|
31
|
+
navigation: {
|
|
32
|
+
resolveRenameNewName: shared_1.camelize,
|
|
33
|
+
resolveRenameEditText: getPropRenameApply(prop.name),
|
|
34
|
+
},
|
|
35
|
+
}), `)(`, ...(prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
36
|
+
? (0, common_1.wrapWith)(prop.exp.loc.start.offset, prop.exp.loc.end.offset, ctx.codeFeatures.verification, ...(0, interpolation_1.generateInterpolation)(options, ctx, prop.exp.content, prop.exp.loc, prop.exp.loc.start.offset, ctx.codeFeatures.all, '(', ')'))
|
|
37
|
+
: [`undefined`]), `)`);
|
|
38
|
+
yield common_1.endOfLine;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.generateElementDirectives = generateElementDirectives;
|
|
43
|
+
function getPropRenameApply(oldName) {
|
|
44
|
+
return oldName === (0, shared_2.hyphenateAttr)(oldName) ? shared_2.hyphenateAttr : undefined;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=elementDirectives.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as CompilerDOM from '@vue/compiler-dom';
|
|
2
|
+
import type * as ts from 'typescript';
|
|
3
|
+
import type { Code } from '../../types';
|
|
4
|
+
import type { TemplateCodegenContext } from './context';
|
|
5
|
+
import type { TemplateCodegenOptions } from './index';
|
|
6
|
+
export declare function generateElementEvents(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, componentVar: string, componentInstanceVar: string, eventsVar: string, used: () => void): Generator<Code>;
|
|
7
|
+
export declare function generateEventArg(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, arg: CompilerDOM.SimpleExpressionNode, access: boolean): Generator<Code>;
|
|
8
|
+
export declare function generateEventExpression(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode): Generator<Code>;
|
|
9
|
+
export declare function isCompoundExpression(ts: typeof import('typescript'), ast: ts.SourceFile): boolean;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isCompoundExpression = exports.generateEventExpression = exports.generateEventArg = exports.generateElementEvents = void 0;
|
|
4
|
+
const CompilerDOM = require("@vue/compiler-dom");
|
|
5
|
+
const shared_1 = require("@vue/shared");
|
|
6
|
+
const shared_2 = require("../../utils/shared");
|
|
7
|
+
const common_1 = require("../common");
|
|
8
|
+
const camelized_1 = require("./camelized");
|
|
9
|
+
const interpolation_1 = require("./interpolation");
|
|
10
|
+
const objectProperty_1 = require("./objectProperty");
|
|
11
|
+
function* generateElementEvents(options, ctx, node, componentVar, componentInstanceVar, eventsVar, used) {
|
|
12
|
+
for (const prop of node.props) {
|
|
13
|
+
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
14
|
+
&& prop.name === 'on'
|
|
15
|
+
&& prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
16
|
+
used();
|
|
17
|
+
const eventVar = ctx.getInternalVariable();
|
|
18
|
+
yield `let ${eventVar} = { '${prop.arg.loc.source}': __VLS_pickEvent(`;
|
|
19
|
+
yield `${eventsVar}['${prop.arg.loc.source}'], `;
|
|
20
|
+
yield `({} as __VLS_FunctionalComponentProps<typeof ${componentVar}, typeof ${componentInstanceVar}>)`;
|
|
21
|
+
yield* generateEventArg(options, ctx, prop.arg, true);
|
|
22
|
+
yield `) }${common_1.endOfLine}`;
|
|
23
|
+
yield `${eventVar} = { `;
|
|
24
|
+
if (prop.arg.loc.source.startsWith('[') && prop.arg.loc.source.endsWith(']')) {
|
|
25
|
+
yield `[(`;
|
|
26
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, prop.arg.loc.source.slice(1, -1), prop.arg.loc, prop.arg.loc.start.offset + 1, ctx.codeFeatures.all, '', '');
|
|
27
|
+
yield `)!]`;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, prop.arg.loc.source, prop.arg.loc.start.offset, ctx.codeFeatures.withoutHighlightAndCompletionAndNavigation, prop.arg.loc);
|
|
31
|
+
}
|
|
32
|
+
yield `: `;
|
|
33
|
+
yield* generateEventExpression(options, ctx, prop);
|
|
34
|
+
yield ` }${common_1.endOfLine}`;
|
|
35
|
+
}
|
|
36
|
+
else if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
37
|
+
&& prop.name === 'on'
|
|
38
|
+
&& prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
39
|
+
// for vue 2 nameless event
|
|
40
|
+
// https://github.com/johnsoncodehk/vue-tsc/issues/67
|
|
41
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, prop.exp.content, prop.exp.loc, prop.exp.loc.start.offset, ctx.codeFeatures.all, '$event => {(', ')}');
|
|
42
|
+
yield common_1.endOfLine;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.generateElementEvents = generateElementEvents;
|
|
47
|
+
const eventArgFeatures = {
|
|
48
|
+
navigation: {
|
|
49
|
+
// @click-outside -> onClickOutside
|
|
50
|
+
resolveRenameNewName(newName) {
|
|
51
|
+
return (0, shared_1.camelize)('on-' + newName);
|
|
52
|
+
},
|
|
53
|
+
// onClickOutside -> @click-outside
|
|
54
|
+
resolveRenameEditText(newName) {
|
|
55
|
+
const hName = (0, shared_2.hyphenateAttr)(newName);
|
|
56
|
+
if ((0, shared_2.hyphenateAttr)(newName).startsWith('on-')) {
|
|
57
|
+
return (0, shared_1.camelize)(hName.slice('on-'.length));
|
|
58
|
+
}
|
|
59
|
+
return newName;
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
function* generateEventArg(options, ctx, arg, access) {
|
|
64
|
+
if (arg.loc.source.startsWith('[') && arg.loc.source.endsWith(']')) {
|
|
65
|
+
yield `[`;
|
|
66
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, arg.loc.source.slice(1, -1), arg.loc, arg.loc.start.offset + 1, ctx.codeFeatures.all, '', '');
|
|
67
|
+
yield `]`;
|
|
68
|
+
}
|
|
69
|
+
else if (common_1.variableNameRegex.test((0, shared_1.camelize)(arg.loc.source))) {
|
|
70
|
+
if (access) {
|
|
71
|
+
yield `.`;
|
|
72
|
+
}
|
|
73
|
+
yield ['', 'template', arg.loc.start.offset, eventArgFeatures];
|
|
74
|
+
yield `on`;
|
|
75
|
+
yield* (0, camelized_1.generateCamelized)((0, shared_1.capitalize)(arg.loc.source), arg.loc.start.offset, common_1.combineLastMapping);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
if (access) {
|
|
79
|
+
yield `[`;
|
|
80
|
+
}
|
|
81
|
+
yield* (0, common_1.wrapWith)(arg.loc.start.offset, arg.loc.end.offset, eventArgFeatures, `'`, ['', 'template', arg.loc.start.offset, common_1.combineLastMapping], 'on', ...(0, camelized_1.generateCamelized)((0, shared_1.capitalize)(arg.loc.source), arg.loc.start.offset, common_1.combineLastMapping), `'`);
|
|
82
|
+
if (access) {
|
|
83
|
+
yield `]`;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.generateEventArg = generateEventArg;
|
|
88
|
+
function* generateEventExpression(options, ctx, prop) {
|
|
89
|
+
if (prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
90
|
+
let prefix = '(';
|
|
91
|
+
let suffix = ')';
|
|
92
|
+
let isFirstMapping = true;
|
|
93
|
+
const ast = (0, common_1.createTsAst)(options.ts, prop.exp, prop.exp.content);
|
|
94
|
+
const _isCompoundExpression = isCompoundExpression(options.ts, ast);
|
|
95
|
+
if (_isCompoundExpression) {
|
|
96
|
+
yield `$event => {${common_1.newLine}`;
|
|
97
|
+
ctx.addLocalVariable('$event');
|
|
98
|
+
prefix = '';
|
|
99
|
+
suffix = '';
|
|
100
|
+
for (const blockCondition of ctx.blockConditions) {
|
|
101
|
+
prefix += `if (!(${blockCondition})) return${common_1.endOfLine}`;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, prop.exp.content, prop.exp.loc, prop.exp.loc.start.offset, () => {
|
|
105
|
+
if (_isCompoundExpression && isFirstMapping) {
|
|
106
|
+
isFirstMapping = false;
|
|
107
|
+
return {
|
|
108
|
+
...ctx.codeFeatures.all,
|
|
109
|
+
__hint: {
|
|
110
|
+
setting: 'vue.inlayHints.inlineHandlerLeading',
|
|
111
|
+
label: '$event =>',
|
|
112
|
+
tooltip: [
|
|
113
|
+
'`$event` is a hidden parameter, you can use it in this callback.',
|
|
114
|
+
'To hide this hint, set `vue.inlayHints.inlineHandlerLeading` to `false` in IDE settings.',
|
|
115
|
+
'[More info](https://github.com/vuejs/language-tools/issues/2445#issuecomment-1444771420)',
|
|
116
|
+
].join('\n\n'),
|
|
117
|
+
paddingRight: true,
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
return ctx.codeFeatures.all;
|
|
122
|
+
}, prefix, suffix);
|
|
123
|
+
if (_isCompoundExpression) {
|
|
124
|
+
ctx.removeLocalVariable('$event');
|
|
125
|
+
yield common_1.endOfLine;
|
|
126
|
+
yield* ctx.generateAutoImportCompletion();
|
|
127
|
+
yield `}`;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
yield `() => {}`;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
exports.generateEventExpression = generateEventExpression;
|
|
135
|
+
function isCompoundExpression(ts, ast) {
|
|
136
|
+
let result = true;
|
|
137
|
+
if (ast.statements.length === 1) {
|
|
138
|
+
ts.forEachChild(ast, child_1 => {
|
|
139
|
+
if (ts.isExpressionStatement(child_1)) {
|
|
140
|
+
ts.forEachChild(child_1, child_2 => {
|
|
141
|
+
if (ts.isArrowFunction(child_2)) {
|
|
142
|
+
result = false;
|
|
143
|
+
}
|
|
144
|
+
else if (ts.isIdentifier(child_2)) {
|
|
145
|
+
result = false;
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
else if (ts.isFunctionDeclaration(child_1)) {
|
|
150
|
+
result = false;
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
return result;
|
|
155
|
+
}
|
|
156
|
+
exports.isCompoundExpression = isCompoundExpression;
|
|
157
|
+
//# sourceMappingURL=elementEvents.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import * as CompilerDOM from '@vue/compiler-dom';
|
|
2
|
+
import type { Code } from '../../types';
|
|
3
|
+
import type { TemplateCodegenContext } from './context';
|
|
4
|
+
import type { TemplateCodegenOptions } from './index';
|
|
5
|
+
export declare function generateElementProps(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, props: CompilerDOM.ElementNode['props'], enableCodeFeatures: boolean, propsFailedExps?: CompilerDOM.SimpleExpressionNode[]): Generator<Code>;
|