@vue/language-core 1.7.0

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.
Files changed (54) hide show
  1. package/LICENSE +21 -0
  2. package/out/generators/script.d.ts +14 -0
  3. package/out/generators/script.js +881 -0
  4. package/out/generators/template.d.ts +16 -0
  5. package/out/generators/template.js +1389 -0
  6. package/out/index.d.ts +12 -0
  7. package/out/index.js +30 -0
  8. package/out/languageModule.d.ts +5 -0
  9. package/out/languageModule.js +91 -0
  10. package/out/parsers/scriptRanges.d.ts +15 -0
  11. package/out/parsers/scriptRanges.js +58 -0
  12. package/out/parsers/scriptSetupRanges.d.ts +32 -0
  13. package/out/parsers/scriptSetupRanges.js +295 -0
  14. package/out/plugins/file-html.d.ts +3 -0
  15. package/out/plugins/file-html.js +80 -0
  16. package/out/plugins/file-md.d.ts +3 -0
  17. package/out/plugins/file-md.js +62 -0
  18. package/out/plugins/file-vue.d.ts +3 -0
  19. package/out/plugins/file-vue.js +39 -0
  20. package/out/plugins/vue-sfc-customblocks.d.ts +3 -0
  21. package/out/plugins/vue-sfc-customblocks.js +31 -0
  22. package/out/plugins/vue-sfc-scripts.d.ts +3 -0
  23. package/out/plugins/vue-sfc-scripts.js +39 -0
  24. package/out/plugins/vue-sfc-styles.d.ts +3 -0
  25. package/out/plugins/vue-sfc-styles.js +31 -0
  26. package/out/plugins/vue-sfc-template.d.ts +3 -0
  27. package/out/plugins/vue-sfc-template.js +27 -0
  28. package/out/plugins/vue-template-html.d.ts +3 -0
  29. package/out/plugins/vue-template-html.js +165 -0
  30. package/out/plugins/vue-tsx.d.ts +14 -0
  31. package/out/plugins/vue-tsx.js +158 -0
  32. package/out/plugins.d.ts +23 -0
  33. package/out/plugins.js +52 -0
  34. package/out/sourceFile.d.ts +71 -0
  35. package/out/sourceFile.js +528 -0
  36. package/out/types.d.ts +100 -0
  37. package/out/types.js +3 -0
  38. package/out/utils/directorySharedTypes.d.ts +6 -0
  39. package/out/utils/directorySharedTypes.js +169 -0
  40. package/out/utils/parseCssClassNames.d.ts +4 -0
  41. package/out/utils/parseCssClassNames.js +19 -0
  42. package/out/utils/parseCssVars.d.ts +5 -0
  43. package/out/utils/parseCssVars.js +26 -0
  44. package/out/utils/parseSfc.d.ts +2 -0
  45. package/out/utils/parseSfc.js +135 -0
  46. package/out/utils/shared.d.ts +1 -0
  47. package/out/utils/shared.js +8 -0
  48. package/out/utils/transform.d.ts +8 -0
  49. package/out/utils/transform.js +182 -0
  50. package/out/utils/ts.d.ts +8 -0
  51. package/out/utils/ts.js +196 -0
  52. package/out/utils/vue2TemplateCompiler.d.ts +3 -0
  53. package/out/utils/vue2TemplateCompiler.js +101 -0
  54. package/package.json +29 -0
@@ -0,0 +1,1389 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.walkElementNodes = exports.generate = void 0;
4
+ const language_core_1 = require("@volar/language-core");
5
+ const CompilerDOM = require("@vue/compiler-dom");
6
+ const shared_1 = require("@vue/shared");
7
+ const transform_1 = require("../utils/transform");
8
+ const minimatch_1 = require("minimatch");
9
+ const muggle = require("muggle-string");
10
+ const capabilitiesPresets = {
11
+ all: language_core_1.FileRangeCapabilities.full,
12
+ allWithHiddenParam: {
13
+ ...language_core_1.FileRangeCapabilities.full, __hint: {
14
+ setting: 'vue.inlayHints.inlineHandlerLeading',
15
+ label: '$event =>',
16
+ tooltip: [
17
+ '`$event` is a hidden parameter, you can use it in this callback.',
18
+ 'To hide this hint, set `vue.inlayHints.inlineHandlerLeading` to `false` in IDE settings.',
19
+ '[More info](https://github.com/vuejs/language-tools/issues/2445#issuecomment-1444771420)',
20
+ ].join('\n\n'),
21
+ paddingRight: true,
22
+ } /* TODO */
23
+ },
24
+ noDiagnostic: { ...language_core_1.FileRangeCapabilities.full, diagnostic: false },
25
+ diagnosticOnly: { diagnostic: true },
26
+ tagHover: { hover: true },
27
+ event: { hover: true, diagnostic: true },
28
+ tagReference: { references: true, definition: true, rename: { normalize: undefined, apply: noEditApply } },
29
+ attr: { hover: true, diagnostic: true, references: true, definition: true, rename: true },
30
+ attrReference: { references: true, definition: true, rename: true },
31
+ slotProp: { references: true, definition: true, rename: true, diagnostic: true },
32
+ scopedClassName: { references: true, definition: true, rename: true, completion: true },
33
+ slotName: { hover: true, diagnostic: true, references: true, definition: true, completion: true },
34
+ slotNameExport: { hover: true, diagnostic: true, references: true, definition: true, /* referencesCodeLens: true */ },
35
+ refAttr: { references: true, definition: true, rename: true },
36
+ };
37
+ const formatBrackets = {
38
+ normal: ['`${', '}`;'],
39
+ // fix https://github.com/vuejs/language-tools/issues/1210
40
+ // fix https://github.com/vuejs/language-tools/issues/2305
41
+ curly: ['0 +', '+ 0;'],
42
+ event: ['() => ', ';'],
43
+ };
44
+ const validTsVar = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
45
+ // @ts-ignore
46
+ const transformContext = {
47
+ onError: () => { },
48
+ helperString: str => str.toString(),
49
+ replaceNode: () => { },
50
+ cacheHandlers: false,
51
+ prefixIdentifiers: false,
52
+ scopes: {
53
+ vFor: 0,
54
+ vOnce: 0,
55
+ vPre: 0,
56
+ vSlot: 0,
57
+ },
58
+ expressionPlugins: ['typescript'],
59
+ };
60
+ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourceLang, templateAst, hasScriptSetupSlots, sharedTypesImport, cssScopedClasses = []) {
61
+ const codes = [];
62
+ const formatCodes = [];
63
+ const cssCodes = [];
64
+ const slots = new Map();
65
+ const slotExps = new Map();
66
+ const cssScopedClassesSet = new Set(cssScopedClasses);
67
+ const tagNames = collectTagOffsets();
68
+ const localVars = {};
69
+ const tempVars = [];
70
+ const identifiers = new Set();
71
+ const scopedClasses = [];
72
+ const blockConditions = [];
73
+ let hasSlot = false;
74
+ let elementIndex = 0;
75
+ const componentVars = generateComponentVars();
76
+ visitNode(templateAst, undefined, undefined);
77
+ generateStyleScopedClasses();
78
+ if (!hasScriptSetupSlots) {
79
+ codes.push('var __VLS_slots!:', ...createSlotsTypeCode(), ';\n');
80
+ }
81
+ generateAutoImportCompletionCode();
82
+ return {
83
+ codes,
84
+ formatCodes,
85
+ cssCodes,
86
+ tagNames,
87
+ identifiers,
88
+ hasSlot,
89
+ };
90
+ function createSlotsTypeCode() {
91
+ const codes = [];
92
+ for (const [exp, slot] of slotExps) {
93
+ hasSlot = true;
94
+ codes.push(`Partial<Record<NonNullable<typeof ${exp}>, (_: typeof ${slot.varName}) => any>> &\n`);
95
+ }
96
+ codes.push(`{\n`);
97
+ for (const [name, slot] of slots) {
98
+ hasSlot = true;
99
+ codes.push(...createObjectPropertyCode([
100
+ name,
101
+ 'template',
102
+ slot.loc,
103
+ {
104
+ ...capabilitiesPresets.slotNameExport,
105
+ referencesCodeLens: true,
106
+ },
107
+ ], slot.nodeLoc));
108
+ codes.push(`?(_: typeof ${slot.varName}): any,\n`);
109
+ }
110
+ codes.push(`}`);
111
+ return codes;
112
+ }
113
+ function generateStyleScopedClasses() {
114
+ codes.push(`if (typeof __VLS_styleScopedClasses === 'object' && !Array.isArray(__VLS_styleScopedClasses)) {\n`);
115
+ for (const { className, offset } of scopedClasses) {
116
+ codes.push(`__VLS_styleScopedClasses[`);
117
+ codes.push(...createStringLiteralKeyCode([
118
+ className,
119
+ 'template',
120
+ offset,
121
+ {
122
+ ...capabilitiesPresets.scopedClassName,
123
+ displayWithLink: cssScopedClassesSet.has(className),
124
+ },
125
+ ]));
126
+ codes.push(`];\n`);
127
+ }
128
+ codes.push('}\n');
129
+ }
130
+ function generateComponentVars() {
131
+ const data = {};
132
+ codes.push(`let __VLS_templateComponents!: {}\n`);
133
+ for (const tagName in tagNames) {
134
+ const isNamespacedTag = tagName.indexOf('.') >= 0;
135
+ if (isNamespacedTag)
136
+ continue;
137
+ const varName = validTsVar.test(tagName) ? tagName : (0, shared_1.capitalize)((0, shared_1.camelize)(tagName.replace(/:/g, '-')));
138
+ codes.push(`& import('${sharedTypesImport}').WithComponent<'${varName}', typeof __VLS_components, `,
139
+ // order is important: https://github.com/vuejs/language-tools/issues/2010
140
+ `"${(0, shared_1.capitalize)((0, shared_1.camelize)(tagName))}", `, `"${(0, shared_1.camelize)(tagName)}", `, `"${tagName}"`, '>\n');
141
+ data[tagName] = varName;
142
+ }
143
+ codes.push(`;\n`);
144
+ for (const tagName in tagNames) {
145
+ const varName = data[tagName];
146
+ if (!varName)
147
+ continue;
148
+ const tagOffsets = tagNames[tagName];
149
+ const tagRanges = tagOffsets.map(offset => [offset, offset + tagName.length]);
150
+ const names = new Set([
151
+ // order is important: https://github.com/vuejs/language-tools/issues/2010
152
+ (0, shared_1.capitalize)((0, shared_1.camelize)(tagName)),
153
+ (0, shared_1.camelize)(tagName),
154
+ tagName,
155
+ ]);
156
+ for (const name of names) {
157
+ for (const tagRange of tagRanges) {
158
+ codes.push(name === tagName ? '__VLS_templateComponents' : '__VLS_components', ...createPropertyAccessCode([
159
+ name,
160
+ 'template',
161
+ tagRange,
162
+ {
163
+ ...capabilitiesPresets.tagReference,
164
+ rename: {
165
+ normalize: tagName === name ? capabilitiesPresets.tagReference.rename.normalize : camelizeComponentName,
166
+ apply: getRenameApply(tagName),
167
+ },
168
+ },
169
+ ]), ';');
170
+ }
171
+ }
172
+ codes.push('\n');
173
+ codes.push('// @ts-ignore\n', // #2304
174
+ '[');
175
+ for (const tagRange of tagRanges) {
176
+ codes.push([
177
+ varName,
178
+ 'template',
179
+ tagRange,
180
+ {
181
+ completion: {
182
+ additional: true,
183
+ autoImportOnly: true,
184
+ },
185
+ },
186
+ ]);
187
+ codes.push(',');
188
+ }
189
+ codes.push(`];\n`);
190
+ }
191
+ return data;
192
+ }
193
+ function collectTagOffsets() {
194
+ const tagOffsetsMap = {};
195
+ walkElementNodes(templateAst, node => {
196
+ if (node.tag === 'slot') {
197
+ // ignore
198
+ }
199
+ else if (node.tag === 'component' || node.tag === 'Component') {
200
+ for (const prop of node.props) {
201
+ if (prop.type === 6 /* CompilerDOM.NodeTypes.ATTRIBUTE */ && prop.name === 'is' && prop.value) {
202
+ const tag = prop.value.content;
203
+ tagOffsetsMap[tag] ??= [];
204
+ tagOffsetsMap[tag].push(prop.value.loc.start.offset + prop.value.loc.source.lastIndexOf(tag));
205
+ break;
206
+ }
207
+ }
208
+ }
209
+ else {
210
+ tagOffsetsMap[node.tag] ??= [];
211
+ const offsets = tagOffsetsMap[node.tag];
212
+ const source = sourceTemplate.substring(node.loc.start.offset);
213
+ const startTagOffset = node.loc.start.offset + source.indexOf(node.tag);
214
+ offsets.push(startTagOffset); // start tag
215
+ if (!node.isSelfClosing && sourceLang === 'html') {
216
+ const endTagOffset = node.loc.start.offset + node.loc.source.lastIndexOf(node.tag);
217
+ if (endTagOffset !== startTagOffset) {
218
+ offsets.push(endTagOffset); // end tag
219
+ }
220
+ }
221
+ }
222
+ });
223
+ return tagOffsetsMap;
224
+ }
225
+ function visitNode(node, parentEl, componentCtxVar) {
226
+ if (node.type === 0 /* CompilerDOM.NodeTypes.ROOT */) {
227
+ for (const childNode of node.children) {
228
+ visitNode(childNode, parentEl, componentCtxVar);
229
+ }
230
+ }
231
+ else if (node.type === 1 /* CompilerDOM.NodeTypes.ELEMENT */) {
232
+ const vForNode = getVForNode(node);
233
+ const vIfNode = getVIfNode(node);
234
+ if (vForNode) {
235
+ visitVForNode(vForNode, parentEl, componentCtxVar);
236
+ }
237
+ else if (vIfNode) {
238
+ visitVIfNode(vIfNode, parentEl, componentCtxVar);
239
+ }
240
+ else {
241
+ visitElementNode(node, parentEl, componentCtxVar);
242
+ }
243
+ }
244
+ else if (node.type === 12 /* CompilerDOM.NodeTypes.TEXT_CALL */) {
245
+ // {{ var }}
246
+ visitNode(node.content, parentEl, componentCtxVar);
247
+ }
248
+ else if (node.type === 8 /* CompilerDOM.NodeTypes.COMPOUND_EXPRESSION */) {
249
+ // {{ ... }} {{ ... }}
250
+ for (const childNode of node.children) {
251
+ if (typeof childNode === 'object') {
252
+ visitNode(childNode, parentEl, componentCtxVar);
253
+ }
254
+ }
255
+ }
256
+ else if (node.type === 5 /* CompilerDOM.NodeTypes.INTERPOLATION */) {
257
+ // {{ ... }}
258
+ let content = node.content.loc.source;
259
+ let start = node.content.loc.start.offset;
260
+ let leftCharacter;
261
+ let rightCharacter;
262
+ // fix https://github.com/vuejs/language-tools/issues/1787
263
+ while ((leftCharacter = sourceTemplate.substring(start - 1, start)).trim() === '' && leftCharacter.length) {
264
+ start--;
265
+ content = leftCharacter + content;
266
+ }
267
+ while ((rightCharacter = sourceTemplate.substring(start + content.length, start + content.length + 1)).trim() === '' && rightCharacter.length) {
268
+ content = content + rightCharacter;
269
+ }
270
+ codes.push(...createInterpolationCode(content, node.content.loc, start, capabilitiesPresets.all, '(', ');\n'));
271
+ const lines = content.split('\n');
272
+ formatCodes.push(...createFormatCode(content, start, lines.length <= 1 ? formatBrackets.curly : [
273
+ formatBrackets.curly[0],
274
+ lines[lines.length - 1].trim() === '' ? '' : formatBrackets.curly[1],
275
+ ]));
276
+ }
277
+ else if (node.type === 9 /* CompilerDOM.NodeTypes.IF */) {
278
+ // v-if / v-else-if / v-else
279
+ visitVIfNode(node, parentEl, componentCtxVar);
280
+ }
281
+ else if (node.type === 11 /* CompilerDOM.NodeTypes.FOR */) {
282
+ // v-for
283
+ visitVForNode(node, parentEl, componentCtxVar);
284
+ }
285
+ else if (node.type === 2 /* CompilerDOM.NodeTypes.TEXT */) {
286
+ // not needed progress
287
+ }
288
+ else if (node.type === 3 /* CompilerDOM.NodeTypes.COMMENT */) {
289
+ // not needed progress
290
+ }
291
+ else {
292
+ codes.push(`// Unprocessed node type: ${node.type} json: ${JSON.stringify(node.loc)}\n`);
293
+ }
294
+ }
295
+ function visitVIfNode(node, parentEl, componentCtxVar) {
296
+ let originalBlockConditionsLength = blockConditions.length;
297
+ for (let i = 0; i < node.branches.length; i++) {
298
+ const branch = node.branches[i];
299
+ if (i === 0)
300
+ codes.push('if');
301
+ else if (branch.condition)
302
+ codes.push('else if');
303
+ else
304
+ codes.push('else');
305
+ let addedBlockCondition = false;
306
+ if (branch.condition?.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */) {
307
+ codes.push(` `);
308
+ const beforeCodeLength = codes.length;
309
+ codes.push(...createInterpolationCode(branch.condition.content, branch.condition.loc, branch.condition.loc.start.offset, capabilitiesPresets.all, '(', ')'));
310
+ const afterCodeLength = codes.length;
311
+ formatCodes.push(...createFormatCode(branch.condition.content, branch.condition.loc.start.offset, formatBrackets.normal));
312
+ blockConditions.push(muggle.toString(codes.slice(beforeCodeLength, afterCodeLength)));
313
+ addedBlockCondition = true;
314
+ }
315
+ codes.push(` {\n`);
316
+ for (const childNode of branch.children) {
317
+ visitNode(childNode, parentEl, componentCtxVar);
318
+ }
319
+ generateAutoImportCompletionCode();
320
+ codes.push('}\n');
321
+ if (addedBlockCondition) {
322
+ blockConditions[blockConditions.length - 1] = `!(${blockConditions[blockConditions.length - 1]})`;
323
+ }
324
+ }
325
+ blockConditions.length = originalBlockConditionsLength;
326
+ }
327
+ function visitVForNode(node, parentEl, componentCtxVar) {
328
+ const { source, value, key, index } = node.parseResult;
329
+ const leftExpressionRange = value ? { start: (value ?? key ?? index).loc.start.offset, end: (index ?? key ?? value).loc.end.offset } : undefined;
330
+ const leftExpressionText = leftExpressionRange ? node.loc.source.substring(leftExpressionRange.start - node.loc.start.offset, leftExpressionRange.end - node.loc.start.offset) : undefined;
331
+ const forBlockVars = [];
332
+ codes.push(`for (const [`);
333
+ if (leftExpressionRange && leftExpressionText) {
334
+ const collectAst = createTsAst(node.parseResult, `const [${leftExpressionText}]`);
335
+ (0, transform_1.colletVars)(ts, collectAst, forBlockVars);
336
+ for (const varName of forBlockVars)
337
+ localVars[varName] = (localVars[varName] ?? 0) + 1;
338
+ codes.push([leftExpressionText, 'template', leftExpressionRange.start, capabilitiesPresets.all]);
339
+ formatCodes.push(...createFormatCode(leftExpressionText, leftExpressionRange.start, formatBrackets.normal));
340
+ }
341
+ codes.push(`] of (await import('${sharedTypesImport}')).getVForSourceType`);
342
+ if (source.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */) {
343
+ codes.push('(', ...createInterpolationCode(source.content, source.loc, source.loc.start.offset, capabilitiesPresets.all, '(', ')'), '!)', // #3102
344
+ ') {\n');
345
+ for (const childNode of node.children) {
346
+ visitNode(childNode, parentEl, componentCtxVar);
347
+ }
348
+ generateAutoImportCompletionCode();
349
+ codes.push('}\n');
350
+ formatCodes.push(...createFormatCode(source.content, source.loc.start.offset, formatBrackets.normal));
351
+ }
352
+ for (const varName of forBlockVars)
353
+ localVars[varName]--;
354
+ }
355
+ function visitElementNode(node, parentEl, componentCtxVar) {
356
+ codes.push(`{\n`);
357
+ const startTagOffset = node.loc.start.offset + sourceTemplate.substring(node.loc.start.offset).indexOf(node.tag);
358
+ let endTagOffset = !node.isSelfClosing && sourceLang === 'html' ? node.loc.start.offset + node.loc.source.lastIndexOf(node.tag) : undefined;
359
+ if (endTagOffset === startTagOffset) {
360
+ endTagOffset = undefined;
361
+ }
362
+ let tag = node.tag;
363
+ let tagOffsets = endTagOffset !== undefined ? [startTagOffset, endTagOffset] : [startTagOffset];
364
+ let props = node.props;
365
+ const propsFailedExps = [];
366
+ const isNamespacedTag = tag.indexOf('.') >= 0;
367
+ const var_originalComponent = `__VLS_${elementIndex++}`;
368
+ const var_functionalComponent = `__VLS_${elementIndex++}`;
369
+ const var_componentInstance = `__VLS_${elementIndex++}`;
370
+ let dynamicTagExp;
371
+ if (tag === 'slot') {
372
+ tagOffsets.length = 0;
373
+ }
374
+ else if (tag === 'component' || tag === 'Component') {
375
+ tagOffsets.length = 0;
376
+ for (const prop of node.props) {
377
+ if (prop.type === 6 /* CompilerDOM.NodeTypes.ATTRIBUTE */ && prop.name === 'is' && prop.value) {
378
+ tag = prop.value.content;
379
+ tagOffsets = [prop.value.loc.start.offset + prop.value.loc.source.lastIndexOf(tag)];
380
+ props = props.filter(p => p !== prop);
381
+ break;
382
+ }
383
+ else if (prop.type === 7 /* CompilerDOM.NodeTypes.DIRECTIVE */ && prop.name === 'bind' && prop.arg?.loc.source === 'is' && prop.exp) {
384
+ dynamicTagExp = prop.exp;
385
+ props = props.filter(p => p !== prop);
386
+ break;
387
+ }
388
+ }
389
+ }
390
+ if (isNamespacedTag) {
391
+ codes.push(`const ${var_originalComponent} = `, ...createInterpolationCode(tag, node.loc, startTagOffset, capabilitiesPresets.all, '', ''), ';\n');
392
+ }
393
+ else if (dynamicTagExp) {
394
+ codes.push(`const ${var_originalComponent} = `, ...createInterpolationCode(dynamicTagExp.loc.source, dynamicTagExp.loc, dynamicTagExp.loc.start.offset, capabilitiesPresets.all, '', ''), ';\n');
395
+ }
396
+ else if (componentVars[tag]) {
397
+ codes.push(`const ${var_originalComponent} = __VLS_templateComponents['${componentVars[tag]}'];\n`);
398
+ }
399
+ else {
400
+ codes.push(`const ${var_originalComponent} = {} as any;\n`);
401
+ }
402
+ codes.push(`const ${var_functionalComponent} = (await import('${sharedTypesImport}')).asFunctionalComponent(`, `${var_originalComponent}, `, `new ${var_originalComponent}({`, ...createPropsCode(node, props, 'extraReferences'), '}));\n');
403
+ for (const offset of tagOffsets) {
404
+ if (isNamespacedTag) {
405
+ continue;
406
+ }
407
+ else if (dynamicTagExp) {
408
+ continue;
409
+ }
410
+ else {
411
+ if (componentVars[tag]) {
412
+ codes.push(`__VLS_templateComponents.`);
413
+ }
414
+ codes.push([
415
+ componentVars[tag] ?? tag,
416
+ 'template',
417
+ [offset, offset + tag.length],
418
+ {
419
+ ...capabilitiesPresets.tagHover,
420
+ ...capabilitiesPresets.diagnosticOnly,
421
+ },
422
+ ], ';\n');
423
+ }
424
+ }
425
+ codes.push(`const ${var_componentInstance} = ${var_functionalComponent}(`,
426
+ // diagnostic start
427
+ tagOffsets.length ? ['', 'template', tagOffsets[0], capabilitiesPresets.diagnosticOnly]
428
+ : dynamicTagExp ? ['', 'template', startTagOffset, capabilitiesPresets.diagnosticOnly]
429
+ : '', '{ ', ...createPropsCode(node, props, 'normal', propsFailedExps), '}',
430
+ // diagnostic end
431
+ tagOffsets.length ? ['', 'template', tagOffsets[0] + tag.length, capabilitiesPresets.diagnosticOnly]
432
+ : dynamicTagExp ? ['', 'template', startTagOffset + tag.length, capabilitiesPresets.diagnosticOnly]
433
+ : '', `, ...(await import('${sharedTypesImport}')).functionalComponentArgsRest(${var_functionalComponent}));\n`);
434
+ if (tag !== 'template' && tag !== 'slot') {
435
+ componentCtxVar = `__VLS_${elementIndex++}`;
436
+ codes.push(`const ${componentCtxVar} = (await import('${sharedTypesImport}')).pickFunctionalComponentCtx(${var_originalComponent}, ${var_componentInstance})!;\n`);
437
+ parentEl = node;
438
+ }
439
+ //#region
440
+ // fix https://github.com/vuejs/language-tools/issues/1775
441
+ for (const failedExp of propsFailedExps) {
442
+ codes.push(...createInterpolationCode(failedExp.loc.source, failedExp.loc, failedExp.loc.start.offset, capabilitiesPresets.all, '(', ')'), ';\n');
443
+ const fb = formatBrackets.normal;
444
+ if (fb) {
445
+ formatCodes.push(...createFormatCode(failedExp.loc.source, failedExp.loc.start.offset, fb));
446
+ }
447
+ }
448
+ generateInlineCss(props);
449
+ const vScope = props.find(prop => prop.type === 7 /* CompilerDOM.NodeTypes.DIRECTIVE */ && (prop.name === 'scope' || prop.name === 'data'));
450
+ let inScope = false;
451
+ let originalConditionsNum = blockConditions.length;
452
+ if (vScope?.type === 7 /* CompilerDOM.NodeTypes.DIRECTIVE */ && vScope.exp) {
453
+ const scopeVar = `__VLS_${elementIndex++}`;
454
+ const condition = `(await import('${sharedTypesImport}')).withScope(__VLS_ctx, ${scopeVar})`;
455
+ codes.push(`const ${scopeVar} = `);
456
+ codes.push([
457
+ vScope.exp.loc.source,
458
+ 'template',
459
+ vScope.exp.loc.start.offset,
460
+ capabilitiesPresets.all,
461
+ ]);
462
+ codes.push(';\n');
463
+ codes.push(`if (${condition}) {\n`);
464
+ blockConditions.push(condition);
465
+ inScope = true;
466
+ }
467
+ generateDirectives(node, var_originalComponent);
468
+ generateElReferences(node); // <el ref="foo" />
469
+ if (cssScopedClasses.length) {
470
+ generateClassScoped(node);
471
+ }
472
+ if (componentCtxVar) {
473
+ generateEvents(node, var_functionalComponent, var_componentInstance, componentCtxVar);
474
+ }
475
+ if (node.tag === 'slot') {
476
+ generateSlot(node, startTagOffset);
477
+ }
478
+ if (inScope) {
479
+ codes.push('}\n');
480
+ blockConditions.length = originalConditionsNum;
481
+ }
482
+ //#endregion
483
+ const slotDir = node.props.find(p => p.type === 7 /* CompilerDOM.NodeTypes.DIRECTIVE */ && p.name === 'slot');
484
+ if (slotDir && componentCtxVar) {
485
+ const slotBlockVars = [];
486
+ codes.push(`{\n`);
487
+ let hasProps = false;
488
+ if (slotDir?.exp?.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */) {
489
+ formatCodes.push(...createFormatCode(slotDir.exp.content, slotDir.exp.loc.start.offset, formatBrackets.normal));
490
+ const collectAst = createTsAst(slotDir, `(${slotDir.exp.content}) => {}`);
491
+ (0, transform_1.colletVars)(ts, collectAst, slotBlockVars);
492
+ hasProps = true;
493
+ if (slotDir.exp.content.indexOf(':') === -1) {
494
+ codes.push('const [', [
495
+ slotDir.exp.content,
496
+ 'template',
497
+ slotDir.exp.loc.start.offset,
498
+ capabilitiesPresets.all,
499
+ ], `] = (await import('${sharedTypesImport}')).getSlotParams(`);
500
+ }
501
+ else {
502
+ codes.push('const ', [
503
+ slotDir.exp.content,
504
+ 'template',
505
+ slotDir.exp.loc.start.offset,
506
+ capabilitiesPresets.all,
507
+ ], ` = (await import('${sharedTypesImport}')).getSlotParam(`);
508
+ }
509
+ }
510
+ codes.push(['', 'template', (slotDir.arg ?? slotDir).loc.start.offset, capabilitiesPresets.diagnosticOnly], `${componentCtxVar}.slots!`, ...((slotDir?.arg?.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */ && slotDir.arg.content)
511
+ ? createPropertyAccessCode([
512
+ slotDir.arg.loc.source,
513
+ 'template',
514
+ slotDir.arg.loc.start.offset,
515
+ slotDir.arg.isStatic ? capabilitiesPresets.slotName : capabilitiesPresets.all
516
+ ], slotDir.arg.loc)
517
+ : createPropertyAccessCode([
518
+ 'default',
519
+ 'template',
520
+ [slotDir.loc.start.offset, slotDir.loc.start.offset + (slotDir.loc.source.startsWith('#') ? '#'.length : slotDir.loc.source.startsWith('v-slot:') ? 'v-slot:'.length : 0)],
521
+ capabilitiesPresets.slotName,
522
+ ])), ['', 'template', (slotDir.arg ?? slotDir).loc.end.offset, capabilitiesPresets.diagnosticOnly]);
523
+ if (hasProps) {
524
+ codes.push(')');
525
+ }
526
+ codes.push(';\n');
527
+ slotBlockVars.forEach(varName => {
528
+ localVars[varName] ??= 0;
529
+ localVars[varName]++;
530
+ });
531
+ for (const childNode of node.children) {
532
+ visitNode(childNode, parentEl, componentCtxVar);
533
+ }
534
+ slotBlockVars.forEach(varName => {
535
+ localVars[varName]--;
536
+ });
537
+ let isStatic = true;
538
+ if (slotDir?.arg?.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */) {
539
+ isStatic = slotDir.arg.isStatic;
540
+ }
541
+ if (isStatic && slotDir && !slotDir.arg) {
542
+ codes.push(`${componentCtxVar}.slots!['`, [
543
+ '',
544
+ 'template',
545
+ slotDir.loc.start.offset + (slotDir.loc.source.startsWith('#') ? '#'.length : slotDir.loc.source.startsWith('v-slot:') ? 'v-slot:'.length : 0),
546
+ { completion: true },
547
+ ], `'/* empty slot name completion */]\n`);
548
+ }
549
+ codes.push(`}\n`);
550
+ }
551
+ else {
552
+ for (const childNode of node.children) {
553
+ visitNode(childNode, parentEl, componentCtxVar);
554
+ }
555
+ }
556
+ codes.push(`}\n`);
557
+ }
558
+ function generateEvents(node, componentVar, componentInstanceVar, componentCtxVar) {
559
+ for (const prop of node.props) {
560
+ if (prop.type === 7 /* CompilerDOM.NodeTypes.DIRECTIVE */
561
+ && prop.name === 'on'
562
+ && prop.arg?.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */) {
563
+ const eventVar = `__VLS_${elementIndex++}`;
564
+ codes.push(`let ${eventVar} = { '${prop.arg.loc.source}': `, `(await import('${sharedTypesImport}')).pickEvent(${componentCtxVar}.emit!, '${prop.arg.loc.source}' as const, (await import('${sharedTypesImport}')).componentProps(${componentVar}, ${componentInstanceVar})`, ...createPropertyAccessCode([
565
+ (0, shared_1.camelize)('on-' + prop.arg.loc.source),
566
+ 'template',
567
+ [prop.arg.loc.start.offset, prop.arg.loc.end.offset],
568
+ {
569
+ ...capabilitiesPresets.attrReference,
570
+ rename: {
571
+ normalize(newName) {
572
+ return (0, shared_1.camelize)('on-' + newName);
573
+ },
574
+ apply(newName) {
575
+ const hName = (0, shared_1.hyphenate)(newName);
576
+ if ((0, shared_1.hyphenate)(newName).startsWith('on-')) {
577
+ return (0, shared_1.camelize)(hName.slice('on-'.length));
578
+ }
579
+ return newName;
580
+ },
581
+ },
582
+ },
583
+ ]), `) };\n`, `${eventVar} = {\n`);
584
+ if (prop.arg.loc.source.startsWith('[') && prop.arg.loc.source.endsWith(']')) {
585
+ codes.push('[(', ...createInterpolationCode(prop.arg.loc.source.slice(1, -1), prop.arg.loc, prop.arg.loc.start.offset + 1, capabilitiesPresets.all, '', ''), ')!]');
586
+ }
587
+ else {
588
+ codes.push(...createObjectPropertyCode([
589
+ prop.arg.loc.source,
590
+ 'template',
591
+ prop.arg.loc.start.offset,
592
+ capabilitiesPresets.event,
593
+ ], prop.arg.loc));
594
+ }
595
+ codes.push(`: `);
596
+ appendExpressionNode(prop);
597
+ codes.push(`};\n`);
598
+ }
599
+ else if (prop.type === 7 /* CompilerDOM.NodeTypes.DIRECTIVE */
600
+ && prop.name === 'on'
601
+ && prop.exp?.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */) {
602
+ // for vue 2 nameless event
603
+ // https://github.com/johnsoncodehk/vue-tsc/issues/67
604
+ codes.push(...createInterpolationCode(prop.exp.content, prop.exp.loc, prop.exp.loc.start.offset, capabilitiesPresets.all, '$event => {(', ')}'), ';\n');
605
+ formatCodes.push(...createFormatCode(prop.exp.content, prop.exp.loc.start.offset, formatBrackets.normal));
606
+ }
607
+ function appendExpressionNode(prop) {
608
+ if (prop.exp?.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */) {
609
+ const ast = createTsAst(prop.exp, prop.exp.content);
610
+ let isCompoundExpression = true;
611
+ if (ast.getChildCount() === 2) { // with EOF
612
+ ast.forEachChild(child_1 => {
613
+ if (ts.isExpressionStatement(child_1)) {
614
+ child_1.forEachChild(child_2 => {
615
+ if (ts.isArrowFunction(child_2)) {
616
+ isCompoundExpression = false;
617
+ }
618
+ else if (ts.isIdentifier(child_2)) {
619
+ isCompoundExpression = false;
620
+ }
621
+ });
622
+ }
623
+ else if (ts.isFunctionDeclaration(child_1)) {
624
+ isCompoundExpression = false;
625
+ }
626
+ });
627
+ }
628
+ let prefix = '(';
629
+ let suffix = ')';
630
+ if (isCompoundExpression) {
631
+ prefix = '$event => {\n';
632
+ for (const blockCondition of blockConditions) {
633
+ prefix += `if (!(${blockCondition})) return;\n`;
634
+ }
635
+ suffix = '\n}';
636
+ }
637
+ let isFirstMapping = true;
638
+ codes.push(...createInterpolationCode(prop.exp.content, prop.exp.loc, prop.exp.loc.start.offset, () => {
639
+ if (isCompoundExpression && isFirstMapping) {
640
+ isFirstMapping = false;
641
+ return capabilitiesPresets.allWithHiddenParam;
642
+ }
643
+ return capabilitiesPresets.all;
644
+ }, prefix, suffix));
645
+ formatCodes.push(...createFormatCode(prop.exp.content, prop.exp.loc.start.offset, isCompoundExpression ? formatBrackets.event : formatBrackets.normal));
646
+ }
647
+ else {
648
+ codes.push(`() => {}`);
649
+ }
650
+ }
651
+ }
652
+ }
653
+ function createPropsCode(node, props, mode, propsFailedExps) {
654
+ let styleAttrNum = 0;
655
+ let classAttrNum = 0;
656
+ if (props.some(prop => prop.type === 7 /* CompilerDOM.NodeTypes.DIRECTIVE */
657
+ && prop.name === 'bind'
658
+ && !prop.arg
659
+ && prop.exp?.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */)) {
660
+ // fix https://github.com/vuejs/language-tools/issues/2166
661
+ styleAttrNum++;
662
+ classAttrNum++;
663
+ }
664
+ const codes = [];
665
+ let caps_all = capabilitiesPresets.all;
666
+ let caps_diagnosticOnly = capabilitiesPresets.diagnosticOnly;
667
+ let caps_attr = capabilitiesPresets.attr;
668
+ if (mode === 'extraReferences') {
669
+ caps_all = {
670
+ references: caps_all.references,
671
+ rename: caps_all.rename,
672
+ };
673
+ caps_diagnosticOnly = {
674
+ references: caps_diagnosticOnly.references,
675
+ rename: caps_diagnosticOnly.rename,
676
+ };
677
+ caps_attr = {
678
+ references: caps_attr.references,
679
+ rename: caps_attr.rename,
680
+ };
681
+ }
682
+ codes.push(`...{ `);
683
+ for (const prop of props) {
684
+ if (prop.type === 7 /* CompilerDOM.NodeTypes.DIRECTIVE */
685
+ && prop.name === 'on'
686
+ && prop.arg?.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */) {
687
+ codes.push(...createObjectPropertyCode((0, shared_1.camelize)('on-' + prop.arg.loc.source)), ': {} as any, ');
688
+ }
689
+ }
690
+ codes.push(`}, `);
691
+ for (const prop of props) {
692
+ if (prop.type === 7 /* CompilerDOM.NodeTypes.DIRECTIVE */
693
+ && (prop.name === 'bind' || prop.name === 'model')
694
+ && (prop.name === 'model' || prop.arg?.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */)
695
+ && (!prop.exp || prop.exp.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */)) {
696
+ let attrNameText = prop.arg?.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */
697
+ ? prop.arg.constType === 3 /* CompilerDOM.ConstantTypes.CAN_STRINGIFY */
698
+ ? prop.arg.content
699
+ : prop.arg.loc.source
700
+ : getModelValuePropName(node, vueCompilerOptions.target, vueCompilerOptions);
701
+ if (prop.modifiers.some(m => m === 'prop' || m === 'attr')) {
702
+ attrNameText = attrNameText?.substring(1);
703
+ }
704
+ if (attrNameText === undefined
705
+ || vueCompilerOptions.dataAttributes.some(pattern => (0, minimatch_1.minimatch)(attrNameText, pattern))
706
+ || (attrNameText === 'style' && ++styleAttrNum >= 2)
707
+ || (attrNameText === 'class' && ++classAttrNum >= 2)
708
+ || (attrNameText === 'name' && node.tag === 'slot') // #2308
709
+ ) {
710
+ if (prop.exp && prop.exp.constType !== 3 /* CompilerDOM.ConstantTypes.CAN_STRINGIFY */) {
711
+ propsFailedExps?.push(prop.exp);
712
+ }
713
+ continue;
714
+ }
715
+ const isStatic = !prop.arg || (prop.arg.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */ && prop.arg.isStatic);
716
+ const propName = isStatic
717
+ && (0, shared_1.hyphenate)(attrNameText) === attrNameText
718
+ && !vueCompilerOptions.htmlAttributes.some(pattern => (0, minimatch_1.minimatch)(attrNameText, pattern))
719
+ ? (0, shared_1.camelize)(attrNameText)
720
+ : attrNameText;
721
+ if (vueCompilerOptions.strictTemplates) {
722
+ attrNameText = propName;
723
+ }
724
+ // camelize name
725
+ codes.push([
726
+ '',
727
+ 'template',
728
+ prop.loc.start.offset,
729
+ caps_diagnosticOnly,
730
+ ]);
731
+ if (!prop.arg) {
732
+ codes.push(...createObjectPropertyCode([
733
+ attrNameText,
734
+ 'template',
735
+ [prop.loc.start.offset, prop.loc.start.offset + prop.loc.source.indexOf('=')],
736
+ caps_attr,
737
+ ], prop.loc.name_1 ?? (prop.loc.name_1 = {})));
738
+ }
739
+ else if (prop.exp?.constType === 3 /* CompilerDOM.ConstantTypes.CAN_STRINGIFY */) {
740
+ codes.push(...createObjectPropertyCode([
741
+ propName,
742
+ 'template',
743
+ [prop.arg.loc.start.offset, prop.arg.loc.start.offset + attrNameText.length],
744
+ {
745
+ ...caps_attr,
746
+ rename: {
747
+ normalize: shared_1.camelize,
748
+ apply: getRenameApply(attrNameText),
749
+ },
750
+ },
751
+ ], prop.loc.name_2 ?? (prop.loc.name_2 = {})));
752
+ }
753
+ else {
754
+ codes.push(...createObjectPropertyCode([
755
+ propName,
756
+ 'template',
757
+ [prop.arg.loc.start.offset, prop.arg.loc.end.offset],
758
+ {
759
+ ...caps_attr,
760
+ rename: {
761
+ normalize: shared_1.camelize,
762
+ apply: getRenameApply(attrNameText),
763
+ },
764
+ },
765
+ ], prop.loc.name_2 ?? (prop.loc.name_2 = {})));
766
+ }
767
+ codes.push(': (');
768
+ if (prop.exp && !(prop.exp.constType === 3 /* CompilerDOM.ConstantTypes.CAN_STRINGIFY */)) { // style='z-index: 2' will compile to {'z-index':'2'}
769
+ codes.push(...createInterpolationCode(prop.exp.loc.source, prop.exp.loc, prop.exp.loc.start.offset, caps_all, '(', ')'));
770
+ if (mode === 'normal') {
771
+ formatCodes.push(...createFormatCode(prop.exp.loc.source, prop.exp.loc.start.offset, formatBrackets.normal));
772
+ }
773
+ }
774
+ else {
775
+ codes.push('{}');
776
+ }
777
+ codes.push(')');
778
+ codes.push([
779
+ '',
780
+ 'template',
781
+ prop.loc.end.offset,
782
+ caps_diagnosticOnly,
783
+ ]);
784
+ codes.push(', ');
785
+ // original name
786
+ if (prop.arg && attrNameText !== propName) {
787
+ codes.push(...createObjectPropertyCode([
788
+ attrNameText,
789
+ 'template',
790
+ [prop.arg.loc.start.offset, prop.arg.loc.end.offset],
791
+ {
792
+ ...caps_attr,
793
+ rename: {
794
+ normalize: shared_1.camelize,
795
+ apply: getRenameApply(attrNameText),
796
+ },
797
+ },
798
+ ], prop.loc.name_1 ?? (prop.loc.name_1 = {})));
799
+ codes.push(': (');
800
+ if (prop.exp) {
801
+ codes.push(...createInterpolationCode(prop.exp.loc.source, prop.exp.loc, undefined, undefined, '(', ')'));
802
+ }
803
+ else {
804
+ codes.push('undefined');
805
+ }
806
+ codes.push(')');
807
+ codes.push(', ');
808
+ }
809
+ }
810
+ else if (prop.type === 6 /* CompilerDOM.NodeTypes.ATTRIBUTE */) {
811
+ let attrNameText = prop.name;
812
+ if (vueCompilerOptions.dataAttributes.some(pattern => (0, minimatch_1.minimatch)(attrNameText, pattern))
813
+ || (attrNameText === 'style' && ++styleAttrNum >= 2)
814
+ || (attrNameText === 'class' && ++classAttrNum >= 2)
815
+ || (attrNameText === 'name' && node.tag === 'slot') // #2308
816
+ ) {
817
+ continue;
818
+ }
819
+ const propName = (0, shared_1.hyphenate)(prop.name) === prop.name
820
+ && !vueCompilerOptions.htmlAttributes.some(pattern => (0, minimatch_1.minimatch)(attrNameText, pattern))
821
+ ? (0, shared_1.camelize)(prop.name)
822
+ : prop.name;
823
+ if (vueCompilerOptions.strictTemplates) {
824
+ attrNameText = propName;
825
+ }
826
+ // camelize name
827
+ codes.push([
828
+ '',
829
+ 'template',
830
+ prop.loc.start.offset,
831
+ caps_diagnosticOnly,
832
+ ]);
833
+ codes.push(...createObjectPropertyCode([
834
+ propName,
835
+ 'template',
836
+ [prop.loc.start.offset, prop.loc.start.offset + prop.name.length],
837
+ {
838
+ ...caps_attr,
839
+ rename: {
840
+ normalize: shared_1.camelize,
841
+ apply: getRenameApply(prop.name),
842
+ },
843
+ },
844
+ ], prop.loc.name_1 ?? (prop.loc.name_1 = {})));
845
+ codes.push(': (');
846
+ if (prop.value) {
847
+ generateAttrValue(prop.value);
848
+ }
849
+ else {
850
+ codes.push('true');
851
+ }
852
+ codes.push(')');
853
+ codes.push([
854
+ '',
855
+ 'template',
856
+ prop.loc.end.offset,
857
+ caps_diagnosticOnly,
858
+ ]);
859
+ codes.push(', ');
860
+ // original name
861
+ if (attrNameText !== propName) {
862
+ codes.push(...createObjectPropertyCode([
863
+ attrNameText,
864
+ 'template',
865
+ prop.loc.start.offset,
866
+ {
867
+ ...caps_attr,
868
+ rename: {
869
+ normalize: shared_1.camelize,
870
+ apply: getRenameApply(prop.name),
871
+ },
872
+ },
873
+ ], prop.loc.name_2 ?? (prop.loc.name_2 = {})));
874
+ codes.push(': (');
875
+ if (prop.value) {
876
+ generateAttrValue(prop.value);
877
+ }
878
+ else {
879
+ codes.push('true');
880
+ }
881
+ codes.push(')');
882
+ codes.push(', ');
883
+ }
884
+ }
885
+ else if (prop.type === 7 /* CompilerDOM.NodeTypes.DIRECTIVE */
886
+ && prop.name === 'bind'
887
+ && !prop.arg
888
+ && prop.exp?.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */) {
889
+ codes.push('...', ...createInterpolationCode(prop.exp.content, prop.exp.loc, prop.exp.loc.start.offset, caps_all, '(', ')'), ', ');
890
+ if (mode === 'normal') {
891
+ formatCodes.push(...createFormatCode(prop.exp.content, prop.exp.loc.start.offset, formatBrackets.normal));
892
+ }
893
+ }
894
+ else {
895
+ // comment this line to avoid affecting comments in prop expressions
896
+ // tsCodeGen.addText("/* " + [prop.type, prop.name, prop.arg?.loc.source, prop.exp?.loc.source, prop.loc.source].join(", ") + " */ ");
897
+ }
898
+ }
899
+ return codes;
900
+ function generateAttrValue(attrNode) {
901
+ const char = attrNode.loc.source.startsWith("'") ? "'" : '"';
902
+ codes.push(char);
903
+ let start = attrNode.loc.start.offset;
904
+ let end = attrNode.loc.end.offset;
905
+ let content = attrNode.loc.source;
906
+ if ((content.startsWith('"') && content.endsWith('"'))
907
+ || (content.startsWith("'") && content.endsWith("'"))) {
908
+ start++;
909
+ end--;
910
+ content = content.slice(1, -1);
911
+ }
912
+ codes.push([
913
+ toUnicodeIfNeed(content),
914
+ 'template',
915
+ [start, end],
916
+ caps_all,
917
+ ]);
918
+ codes.push(char);
919
+ }
920
+ }
921
+ function generateInlineCss(props) {
922
+ for (const prop of props) {
923
+ if (prop.type === 7 /* CompilerDOM.NodeTypes.DIRECTIVE */
924
+ && prop.name === 'bind'
925
+ && prop.arg?.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */
926
+ && prop.exp?.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */
927
+ && prop.arg.content === 'style'
928
+ && prop.exp.constType === 3 /* CompilerDOM.ConstantTypes.CAN_STRINGIFY */) {
929
+ const endCrt = prop.arg.loc.source[prop.arg.loc.source.length - 1]; // " | '
930
+ const start = prop.arg.loc.source.indexOf(endCrt) + 1;
931
+ const end = prop.arg.loc.source.lastIndexOf(endCrt);
932
+ const content = prop.arg.loc.source.substring(start, end);
933
+ cssCodes.push(`x { `);
934
+ cssCodes.push([
935
+ content,
936
+ 'template',
937
+ prop.arg.loc.start.offset + start,
938
+ capabilitiesPresets.all,
939
+ ]);
940
+ cssCodes.push(` }\n`);
941
+ }
942
+ }
943
+ }
944
+ function generateDirectives(node, componentVar) {
945
+ for (const prop of node.props) {
946
+ if (prop.type === 7 /* CompilerDOM.NodeTypes.DIRECTIVE */
947
+ && prop.name !== 'slot'
948
+ && prop.name !== 'on'
949
+ && prop.name !== 'model'
950
+ && prop.name !== 'bind'
951
+ && (prop.name !== 'scope' && prop.name !== 'data')) {
952
+ identifiers.add((0, shared_1.camelize)('v-' + prop.name));
953
+ if (prop.arg?.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */ && !prop.arg.isStatic) {
954
+ codes.push(...createInterpolationCode(prop.arg.content, prop.arg.loc, prop.arg.loc.start.offset + prop.arg.loc.source.indexOf(prop.arg.content), capabilitiesPresets.all, '(', ')'), ';\n');
955
+ formatCodes.push(...createFormatCode(prop.arg.content, prop.arg.loc.start.offset, formatBrackets.normal));
956
+ }
957
+ codes.push([
958
+ '',
959
+ 'template',
960
+ prop.loc.start.offset,
961
+ capabilitiesPresets.diagnosticOnly,
962
+ ], `(await import('${sharedTypesImport}')).directiveFunction(__VLS_ctx.`, [
963
+ (0, shared_1.camelize)('v-' + prop.name),
964
+ 'template',
965
+ [prop.loc.start.offset, prop.loc.start.offset + 'v-'.length + prop.name.length],
966
+ {
967
+ ...capabilitiesPresets.noDiagnostic,
968
+ completion: {
969
+ // fix https://github.com/vuejs/language-tools/issues/1905
970
+ additional: true,
971
+ },
972
+ rename: {
973
+ normalize: shared_1.camelize,
974
+ apply: getRenameApply(prop.name),
975
+ },
976
+ },
977
+ ], ')', '(', ['', 'template', prop.loc.start.offset, capabilitiesPresets.diagnosticOnly], componentVar, vueCompilerOptions.strictTemplates ? '' : ' as any', ['', 'template', prop.loc.start.offset + 'v-'.length + prop.name.length, capabilitiesPresets.diagnosticOnly], ', ');
978
+ if (prop.exp?.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */) {
979
+ codes.push(['', 'template', prop.exp.loc.start.offset, capabilitiesPresets.diagnosticOnly], ...createInterpolationCode(prop.exp.content, prop.exp.loc, prop.exp.loc.start.offset, capabilitiesPresets.all, '(', ')'), ['', 'template', prop.exp.loc.end.offset, capabilitiesPresets.diagnosticOnly]);
980
+ formatCodes.push(...createFormatCode(prop.exp.content, prop.exp.loc.start.offset, formatBrackets.normal));
981
+ }
982
+ else {
983
+ codes.push('undefined');
984
+ }
985
+ codes.push(')', ['', 'template', prop.loc.end.offset, capabilitiesPresets.diagnosticOnly], ';\n');
986
+ }
987
+ }
988
+ }
989
+ function generateElReferences(node) {
990
+ for (const prop of node.props) {
991
+ if (prop.type === 6 /* CompilerDOM.NodeTypes.ATTRIBUTE */
992
+ && prop.name === 'ref'
993
+ && prop.value) {
994
+ codes.push('// @ts-ignore\n', ...createInterpolationCode(prop.value.content, prop.value.loc, prop.value.loc.start.offset + 1, capabilitiesPresets.refAttr, '(', ')'), ';\n');
995
+ }
996
+ }
997
+ }
998
+ function generateClassScoped(node) {
999
+ for (const prop of node.props) {
1000
+ if (prop.type === 6 /* CompilerDOM.NodeTypes.ATTRIBUTE */
1001
+ && prop.name === 'class'
1002
+ && prop.value) {
1003
+ let startOffset = prop.value.loc.start.offset;
1004
+ let tempClassName = '';
1005
+ for (const char of (prop.value.loc.source + ' ')) {
1006
+ if (char.trim() === '' || char === '"' || char === "'") {
1007
+ if (tempClassName !== '') {
1008
+ scopedClasses.push({ className: tempClassName, offset: startOffset });
1009
+ startOffset += tempClassName.length;
1010
+ tempClassName = '';
1011
+ }
1012
+ startOffset += char.length;
1013
+ }
1014
+ else {
1015
+ tempClassName += char;
1016
+ }
1017
+ }
1018
+ }
1019
+ else if (prop.type === 7 /* CompilerDOM.NodeTypes.DIRECTIVE */
1020
+ && prop.arg?.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */
1021
+ && prop.exp?.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */
1022
+ && prop.arg.content === 'class') {
1023
+ codes.push(`__VLS_styleScopedClasses = (`);
1024
+ codes.push([
1025
+ prop.exp.content,
1026
+ 'template',
1027
+ prop.exp.loc.start.offset,
1028
+ capabilitiesPresets.scopedClassName,
1029
+ ]);
1030
+ codes.push(`);\n`);
1031
+ }
1032
+ }
1033
+ }
1034
+ function generateSlot(node, startTagOffset) {
1035
+ const varSlot = `__VLS_${elementIndex++}`;
1036
+ const slotNameExpNode = getSlotNameExpNode();
1037
+ if (hasScriptSetupSlots) {
1038
+ codes.push(['', 'template', node.loc.start.offset, capabilitiesPresets.diagnosticOnly], '__VLS_slots[', ['', 'template', node.loc.start.offset, capabilitiesPresets.diagnosticOnly], slotNameExpNode?.content ?? `('${getSlotName()}' as const)`, ['', 'template', node.loc.end.offset, capabilitiesPresets.diagnosticOnly], ']', ['', 'template', node.loc.end.offset, capabilitiesPresets.diagnosticOnly], '?.(', ['', 'template', startTagOffset, capabilitiesPresets.diagnosticOnly], '{\n');
1039
+ }
1040
+ else {
1041
+ codes.push(`var ${varSlot} = {\n`);
1042
+ }
1043
+ for (const prop of node.props) {
1044
+ if (prop.type === 7 /* CompilerDOM.NodeTypes.DIRECTIVE */
1045
+ && !prop.arg
1046
+ && prop.exp?.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */) {
1047
+ codes.push('...', ...createInterpolationCode(prop.exp.content, prop.exp.loc, prop.exp.loc.start.offset, capabilitiesPresets.attrReference, '(', ')'), ',\n');
1048
+ }
1049
+ else if (prop.type === 7 /* CompilerDOM.NodeTypes.DIRECTIVE */
1050
+ && prop.arg?.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */
1051
+ && prop.exp?.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */
1052
+ && prop.arg.content !== 'name') {
1053
+ codes.push(...createObjectPropertyCode([
1054
+ prop.arg.content,
1055
+ 'template',
1056
+ [prop.arg.loc.start.offset, prop.arg.loc.end.offset],
1057
+ {
1058
+ ...capabilitiesPresets.slotProp,
1059
+ rename: {
1060
+ normalize: shared_1.camelize,
1061
+ apply: getRenameApply(prop.arg.content),
1062
+ },
1063
+ },
1064
+ ], prop.arg.loc), ': ', ...createInterpolationCode(prop.exp.content, prop.exp.loc, prop.exp.loc.start.offset, capabilitiesPresets.attrReference, '(', ')'), ',\n');
1065
+ }
1066
+ else if (prop.type === 6 /* CompilerDOM.NodeTypes.ATTRIBUTE */
1067
+ && prop.name !== 'name' // slot name
1068
+ ) {
1069
+ codes.push(...createObjectPropertyCode([
1070
+ prop.name,
1071
+ 'template',
1072
+ prop.loc.start.offset,
1073
+ {
1074
+ ...capabilitiesPresets.attr,
1075
+ rename: {
1076
+ normalize: shared_1.camelize,
1077
+ apply: getRenameApply(prop.name),
1078
+ },
1079
+ },
1080
+ ], prop.loc), ': (', prop.value !== undefined ? `"${toUnicodeIfNeed(prop.value.content)}"` : 'true', '),\n');
1081
+ }
1082
+ }
1083
+ codes.push('}', hasScriptSetupSlots ? ['', 'template', startTagOffset + node.tag.length, capabilitiesPresets.diagnosticOnly] : '', hasScriptSetupSlots ? `);\n` : `;\n`);
1084
+ if (hasScriptSetupSlots) {
1085
+ return;
1086
+ }
1087
+ if (slotNameExpNode) {
1088
+ const varSlotExp = `__VLS_${elementIndex++}`;
1089
+ codes.push(`var ${varSlotExp} = `);
1090
+ if (typeof slotNameExpNode === 'string') {
1091
+ codes.push(slotNameExpNode);
1092
+ }
1093
+ else {
1094
+ codes.push(...createInterpolationCode(slotNameExpNode.content, slotNameExpNode, undefined, undefined, '(', ')'));
1095
+ }
1096
+ codes.push(`;\n`);
1097
+ slotExps.set(varSlotExp, {
1098
+ varName: varSlot,
1099
+ });
1100
+ }
1101
+ else {
1102
+ const slotName = getSlotName();
1103
+ slots.set(slotName, {
1104
+ varName: varSlot,
1105
+ loc: [startTagOffset, startTagOffset + node.tag.length],
1106
+ nodeLoc: node.loc,
1107
+ });
1108
+ }
1109
+ function getSlotName() {
1110
+ for (const prop2 of node.props) {
1111
+ if (prop2.name === 'name' && prop2.type === 6 /* CompilerDOM.NodeTypes.ATTRIBUTE */ && prop2.value) {
1112
+ if (prop2.value.content) {
1113
+ return prop2.value.content;
1114
+ }
1115
+ }
1116
+ }
1117
+ return 'default';
1118
+ }
1119
+ function getSlotNameExpNode() {
1120
+ for (const prop2 of node.props) {
1121
+ if (prop2.type === 7 /* CompilerDOM.NodeTypes.DIRECTIVE */ && prop2.name === 'bind' && prop2.arg?.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */ && prop2.arg.content === 'name') {
1122
+ if (prop2.exp?.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */) {
1123
+ return prop2.exp;
1124
+ }
1125
+ }
1126
+ }
1127
+ }
1128
+ }
1129
+ function generateAutoImportCompletionCode() {
1130
+ if (!tempVars.length)
1131
+ return;
1132
+ codes.push('// @ts-ignore\n'); // #2304
1133
+ codes.push('[');
1134
+ for (const _vars of tempVars) {
1135
+ for (const v of _vars) {
1136
+ codes.push([v.text, 'template', v.offset, { completion: { additional: true } }]);
1137
+ codes.push(',');
1138
+ }
1139
+ }
1140
+ codes.push('];\n');
1141
+ tempVars.length = 0;
1142
+ }
1143
+ // functional like
1144
+ function createFormatCode(mapCode, sourceOffset, formatWrapper) {
1145
+ return [
1146
+ formatWrapper[0],
1147
+ [mapCode, 'template', sourceOffset, {}],
1148
+ formatWrapper[1],
1149
+ '\n',
1150
+ ];
1151
+ }
1152
+ function createObjectPropertyCode(a, astHolder) {
1153
+ const aStr = typeof a === 'string' ? a : a[0];
1154
+ if (validTsVar.test(aStr)) {
1155
+ return [a];
1156
+ }
1157
+ else if (aStr.startsWith('[') && aStr.endsWith(']') && astHolder) {
1158
+ const range = typeof a === 'object' ? a[2] : undefined;
1159
+ const data = typeof a === 'object' ? a[3] : undefined;
1160
+ return createInterpolationCode(aStr, astHolder, range && typeof range === 'object' ? range[0] : range, data, '', '');
1161
+ }
1162
+ else {
1163
+ return createStringLiteralKeyCode(a);
1164
+ }
1165
+ }
1166
+ function createInterpolationCode(code, astHolder, start, data, prefix, suffix) {
1167
+ const ast = createTsAst(astHolder, prefix + code + suffix);
1168
+ const codes = [];
1169
+ const vars = (0, transform_1.walkInterpolationFragment)(ts, prefix + code + suffix, ast, (frag, fragOffset, isJustForErrorMapping) => {
1170
+ if (fragOffset === undefined) {
1171
+ codes.push(frag);
1172
+ }
1173
+ else {
1174
+ fragOffset -= prefix.length;
1175
+ let addSuffix = '';
1176
+ const overLength = fragOffset + frag.length - code.length;
1177
+ if (overLength > 0) {
1178
+ addSuffix = frag.substring(frag.length - overLength);
1179
+ frag = frag.substring(0, frag.length - overLength);
1180
+ }
1181
+ if (fragOffset < 0) {
1182
+ codes.push(frag.substring(0, -fragOffset));
1183
+ frag = frag.substring(-fragOffset);
1184
+ fragOffset = 0;
1185
+ }
1186
+ if (start !== undefined && data !== undefined) {
1187
+ codes.push([
1188
+ frag,
1189
+ 'template',
1190
+ start + fragOffset,
1191
+ isJustForErrorMapping
1192
+ ? capabilitiesPresets.diagnosticOnly
1193
+ : typeof data === 'function' ? data() : data,
1194
+ ]);
1195
+ }
1196
+ else {
1197
+ codes.push(frag);
1198
+ }
1199
+ codes.push(addSuffix);
1200
+ }
1201
+ }, localVars, identifiers, vueCompilerOptions);
1202
+ if (start !== undefined) {
1203
+ for (const v of vars) {
1204
+ v.offset = start + v.offset - prefix.length;
1205
+ }
1206
+ if (vars.length) {
1207
+ tempVars.push(vars);
1208
+ }
1209
+ }
1210
+ return codes;
1211
+ }
1212
+ function createTsAst(astHolder, text) {
1213
+ if (astHolder.__volar_ast_text !== text) {
1214
+ astHolder.__volar_ast_text = text;
1215
+ astHolder.__volar_ast = ts.createSourceFile('/a.ts', text, ts.ScriptTarget.ESNext);
1216
+ }
1217
+ return astHolder.__volar_ast;
1218
+ }
1219
+ function createPropertyAccessCode(a, astHolder) {
1220
+ const aStr = typeof a === 'string' ? a : a[0];
1221
+ if (!compilerOptions.noPropertyAccessFromIndexSignature && validTsVar.test(aStr)) {
1222
+ return ['.', a];
1223
+ }
1224
+ else if (aStr.startsWith('[') && aStr.endsWith(']')) {
1225
+ if (typeof a === 'string' || !astHolder) {
1226
+ return [a];
1227
+ }
1228
+ else {
1229
+ return createInterpolationCode(a[0], astHolder, typeof a[2] === 'number' ? a[2] : a[2][0], a[3], '', '');
1230
+ }
1231
+ }
1232
+ else {
1233
+ return ['[', ...createStringLiteralKeyCode(a), ']'];
1234
+ }
1235
+ }
1236
+ function createStringLiteralKeyCode(a) {
1237
+ let codes = ['"', a, '"'];
1238
+ if (typeof a === 'object') {
1239
+ const start = typeof a[2] === 'number' ? a[2] : a[2][0];
1240
+ const end = typeof a[2] === 'number' ? a[2] : a[2][1];
1241
+ codes = [
1242
+ ['', 'template', start, a[3]],
1243
+ ...codes,
1244
+ ['', 'template', end, a[3]],
1245
+ ];
1246
+ }
1247
+ return codes;
1248
+ }
1249
+ }
1250
+ exports.generate = generate;
1251
+ ;
1252
+ function walkElementNodes(node, cb) {
1253
+ if (node.type === 0 /* CompilerDOM.NodeTypes.ROOT */) {
1254
+ for (const child of node.children) {
1255
+ walkElementNodes(child, cb);
1256
+ }
1257
+ }
1258
+ else if (node.type === 1 /* CompilerDOM.NodeTypes.ELEMENT */) {
1259
+ const patchForNode = getVForNode(node);
1260
+ if (patchForNode) {
1261
+ walkElementNodes(patchForNode, cb);
1262
+ }
1263
+ else {
1264
+ cb(node);
1265
+ for (const child of node.children) {
1266
+ walkElementNodes(child, cb);
1267
+ }
1268
+ }
1269
+ }
1270
+ else if (node.type === 9 /* CompilerDOM.NodeTypes.IF */) {
1271
+ // v-if / v-else-if / v-else
1272
+ for (let i = 0; i < node.branches.length; i++) {
1273
+ const branch = node.branches[i];
1274
+ for (const childNode of branch.children) {
1275
+ walkElementNodes(childNode, cb);
1276
+ }
1277
+ }
1278
+ }
1279
+ else if (node.type === 11 /* CompilerDOM.NodeTypes.FOR */) {
1280
+ // v-for
1281
+ for (const child of node.children) {
1282
+ walkElementNodes(child, cb);
1283
+ }
1284
+ }
1285
+ }
1286
+ exports.walkElementNodes = walkElementNodes;
1287
+ function toUnicodeIfNeed(str) {
1288
+ if (str.indexOf('\\') === -1 && str.indexOf('\n') === -1) {
1289
+ return str;
1290
+ }
1291
+ return toUnicode(str);
1292
+ }
1293
+ function toUnicode(str) {
1294
+ return str.split('').map(value => {
1295
+ const temp = value.charCodeAt(0).toString(16).padStart(4, '0');
1296
+ if (temp.length > 2) {
1297
+ return '\\u' + temp;
1298
+ }
1299
+ return value;
1300
+ }).join('');
1301
+ }
1302
+ function camelizeComponentName(newName) {
1303
+ return (0, shared_1.camelize)('-' + newName);
1304
+ }
1305
+ function getRenameApply(oldName) {
1306
+ return oldName === (0, shared_1.hyphenate)(oldName) ? shared_1.hyphenate : noEditApply;
1307
+ }
1308
+ function noEditApply(n) {
1309
+ return n;
1310
+ }
1311
+ function getModelValuePropName(node, vueVersion, vueCompilerOptions) {
1312
+ for (const modelName in vueCompilerOptions.experimentalModelPropName) {
1313
+ const tags = vueCompilerOptions.experimentalModelPropName[modelName];
1314
+ for (const tag in tags) {
1315
+ if (node.tag === tag || node.tag === (0, shared_1.hyphenate)(tag)) {
1316
+ const v = tags[tag];
1317
+ if (typeof v === 'object') {
1318
+ const arr = Array.isArray(v) ? v : [v];
1319
+ for (const attrs of arr) {
1320
+ let failed = false;
1321
+ for (const attr in attrs) {
1322
+ const attrNode = node.props.find(prop => prop.type === 6 /* CompilerDOM.NodeTypes.ATTRIBUTE */ && prop.name === attr);
1323
+ if (!attrNode || attrNode.value?.content !== attrs[attr]) {
1324
+ failed = true;
1325
+ break;
1326
+ }
1327
+ }
1328
+ if (!failed) {
1329
+ // all match
1330
+ return modelName || undefined;
1331
+ }
1332
+ }
1333
+ }
1334
+ }
1335
+ }
1336
+ }
1337
+ for (const modelName in vueCompilerOptions.experimentalModelPropName) {
1338
+ const tags = vueCompilerOptions.experimentalModelPropName[modelName];
1339
+ for (const tag in tags) {
1340
+ if (node.tag === tag || node.tag === (0, shared_1.hyphenate)(tag)) {
1341
+ const attrs = tags[tag];
1342
+ if (attrs === true) {
1343
+ return modelName || undefined;
1344
+ }
1345
+ }
1346
+ }
1347
+ }
1348
+ return vueVersion < 3 ? 'value' : 'modelValue';
1349
+ }
1350
+ // TODO: track https://github.com/vuejs/vue-next/issues/3498
1351
+ function getVForNode(node) {
1352
+ const forDirective = node.props.find((prop) => prop.type === 7 /* CompilerDOM.NodeTypes.DIRECTIVE */
1353
+ && prop.name === 'for');
1354
+ if (forDirective) {
1355
+ let forNode;
1356
+ CompilerDOM.processFor(node, forDirective, transformContext, _forNode => {
1357
+ forNode = { ..._forNode };
1358
+ return undefined;
1359
+ });
1360
+ if (forNode) {
1361
+ forNode.children = [{
1362
+ ...node,
1363
+ props: node.props.filter(prop => prop !== forDirective),
1364
+ }];
1365
+ return forNode;
1366
+ }
1367
+ }
1368
+ }
1369
+ function getVIfNode(node) {
1370
+ const forDirective = node.props.find((prop) => prop.type === 7 /* CompilerDOM.NodeTypes.DIRECTIVE */
1371
+ && prop.name === 'if');
1372
+ if (forDirective) {
1373
+ let ifNode;
1374
+ CompilerDOM.processIf(node, forDirective, transformContext, _ifNode => {
1375
+ ifNode = { ..._ifNode };
1376
+ return undefined;
1377
+ });
1378
+ if (ifNode) {
1379
+ for (const branch of ifNode.branches) {
1380
+ branch.children = [{
1381
+ ...node,
1382
+ props: node.props.filter(prop => prop !== forDirective),
1383
+ }];
1384
+ }
1385
+ return ifNode;
1386
+ }
1387
+ }
1388
+ }
1389
+ //# sourceMappingURL=template.js.map