@vue/language-core 1.9.0-alpha.3 → 2.0.1

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