@vue/language-core 2.0.13 → 2.0.14

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 (85) hide show
  1. package/index.d.ts +1 -1
  2. package/index.js +1 -1
  3. package/lib/codegen/common.d.ts +11 -0
  4. package/lib/codegen/common.js +70 -0
  5. package/lib/codegen/script/component.d.ts +9 -0
  6. package/lib/codegen/script/component.js +101 -0
  7. package/lib/codegen/script/context.d.ts +25 -0
  8. package/lib/codegen/script/context.js +124 -0
  9. package/lib/{generators → codegen/script}/globalTypes.d.ts +1 -1
  10. package/lib/codegen/script/globalTypes.js +135 -0
  11. package/lib/codegen/script/index.d.ts +33 -0
  12. package/lib/codegen/script/index.js +127 -0
  13. package/lib/codegen/script/internalComponent.d.ts +5 -0
  14. package/lib/codegen/script/internalComponent.js +58 -0
  15. package/lib/codegen/script/scriptSetup.d.ts +6 -0
  16. package/lib/codegen/script/scriptSetup.js +338 -0
  17. package/lib/codegen/script/src.d.ts +2 -0
  18. package/lib/codegen/script/src.js +52 -0
  19. package/lib/codegen/script/template.d.ts +5 -0
  20. package/lib/codegen/script/template.js +193 -0
  21. package/lib/codegen/template/camelized.d.ts +2 -0
  22. package/lib/codegen/template/camelized.js +32 -0
  23. package/lib/codegen/template/context.d.ts +44 -0
  24. package/lib/codegen/template/context.js +171 -0
  25. package/lib/codegen/template/element.d.ts +7 -0
  26. package/lib/codegen/template/element.js +325 -0
  27. package/lib/codegen/template/elementChildren.d.ts +5 -0
  28. package/lib/codegen/template/elementChildren.js +21 -0
  29. package/lib/codegen/template/elementDirectives.d.ts +5 -0
  30. package/lib/codegen/template/elementDirectives.js +46 -0
  31. package/lib/codegen/template/elementEvents.d.ts +7 -0
  32. package/lib/codegen/template/elementEvents.js +141 -0
  33. package/lib/codegen/template/elementProps.d.ts +5 -0
  34. package/lib/codegen/template/elementProps.js +250 -0
  35. package/lib/codegen/template/index.d.ts +60 -0
  36. package/lib/codegen/template/index.js +217 -0
  37. package/lib/codegen/template/interpolation.d.ts +6 -0
  38. package/lib/{utils/transform.js → codegen/template/interpolation.js} +76 -46
  39. package/lib/codegen/template/objectProperty.d.ts +4 -0
  40. package/lib/codegen/template/objectProperty.js +31 -0
  41. package/lib/codegen/template/propertyAccess.d.ts +4 -0
  42. package/lib/codegen/template/propertyAccess.js +24 -0
  43. package/lib/codegen/template/slotOutlet.d.ts +5 -0
  44. package/lib/codegen/template/slotOutlet.js +72 -0
  45. package/lib/codegen/template/stringLiteralKey.d.ts +2 -0
  46. package/lib/codegen/template/stringLiteralKey.js +14 -0
  47. package/lib/codegen/template/templateChild.d.ts +7 -0
  48. package/lib/codegen/template/templateChild.js +156 -0
  49. package/lib/codegen/template/vFor.d.ts +12 -0
  50. package/lib/codegen/template/vFor.js +69 -0
  51. package/lib/codegen/template/vIf.d.ts +5 -0
  52. package/lib/codegen/template/vIf.js +53 -0
  53. package/lib/languageModule.d.ts +3 -3
  54. package/lib/languageModule.js +2 -3
  55. package/lib/plugins/shared.d.ts +2 -0
  56. package/lib/plugins/shared.js +12 -0
  57. package/lib/plugins/vue-sfc-customblocks.js +2 -2
  58. package/lib/plugins/vue-sfc-scripts.js +2 -3
  59. package/lib/plugins/vue-sfc-styles.js +3 -3
  60. package/lib/plugins/vue-sfc-template.js +2 -2
  61. package/lib/plugins/vue-template-inline-css.js +34 -2
  62. package/lib/plugins/vue-template-inline-ts.js +10 -8
  63. package/lib/plugins/vue-tsx.d.ts +42 -5
  64. package/lib/plugins/vue-tsx.js +38 -28
  65. package/lib/types.d.ts +1 -3
  66. package/lib/utils/ts.js +0 -29
  67. package/lib/virtualFile/computedFiles.d.ts +1 -1
  68. package/lib/virtualFile/computedFiles.js +22 -12
  69. package/lib/virtualFile/computedMappings.js +3 -3
  70. package/lib/virtualFile/computedSfc.js +22 -1
  71. package/lib/virtualFile/embeddedFile.d.ts +2 -3
  72. package/lib/virtualFile/embeddedFile.js +1 -2
  73. package/lib/virtualFile/vueFile.d.ts +3 -5
  74. package/lib/virtualFile/vueFile.js +6 -8
  75. package/package.json +3 -3
  76. package/lib/generators/globalTypes.js +0 -135
  77. package/lib/generators/inlineCss.d.ts +0 -3
  78. package/lib/generators/inlineCss.js +0 -37
  79. package/lib/generators/script.d.ts +0 -13
  80. package/lib/generators/script.js +0 -981
  81. package/lib/generators/template.d.ts +0 -19
  82. package/lib/generators/template.js +0 -1578
  83. package/lib/generators/utils.d.ts +0 -5
  84. package/lib/generators/utils.js +0 -54
  85. package/lib/utils/transform.d.ts +0 -8
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateCamelized = void 0;
4
+ const shared_1 = require("@vue/shared");
5
+ const common_1 = require("../common");
6
+ function* generateCamelized(code, offset, info) {
7
+ const parts = code.split('-');
8
+ for (let i = 0; i < parts.length; i++) {
9
+ const part = parts[i];
10
+ if (part !== '') {
11
+ if (i === 0) {
12
+ yield [
13
+ part,
14
+ 'template',
15
+ offset,
16
+ info,
17
+ ];
18
+ }
19
+ else {
20
+ yield [
21
+ (0, shared_1.capitalize)(part),
22
+ 'template',
23
+ offset,
24
+ common_1.combineLastMapping,
25
+ ];
26
+ }
27
+ }
28
+ offset += part.length + 1;
29
+ }
30
+ }
31
+ exports.generateCamelized = generateCamelized;
32
+ //# sourceMappingURL=camelized.js.map
@@ -0,0 +1,44 @@
1
+ import type * as CompilerDOM from '@vue/compiler-dom';
2
+ import type { Code, VueCodeInformation } from '../../types';
3
+ export type TemplateCodegenContext = ReturnType<typeof createTemplateCodegenContext>;
4
+ export declare function createTemplateCodegenContext(): {
5
+ slots: {
6
+ name: string;
7
+ loc?: number | undefined;
8
+ tagRange: [number, number];
9
+ varName: string;
10
+ nodeLoc: any;
11
+ }[];
12
+ dynamicSlots: {
13
+ expVar: string;
14
+ varName: string;
15
+ }[];
16
+ codeFeatures: {
17
+ all: VueCodeInformation;
18
+ verification: VueCodeInformation;
19
+ completion: VueCodeInformation;
20
+ additionalCompletion: VueCodeInformation;
21
+ navigation: VueCodeInformation;
22
+ navigationAndCompletion: VueCodeInformation;
23
+ withoutHighlight: VueCodeInformation;
24
+ withoutHighlightAndCompletion: VueCodeInformation;
25
+ withoutHighlightAndCompletionAndNavigation: VueCodeInformation;
26
+ };
27
+ accessGlobalVariables: Map<string, Set<number>>;
28
+ hasSlotElements: Set<CompilerDOM.ElementNode>;
29
+ blockConditions: string[];
30
+ usedComponentCtxVars: Set<string>;
31
+ scopedClasses: {
32
+ className: string;
33
+ offset: number;
34
+ }[];
35
+ accessGlobalVariable(name: string, offset?: number): void;
36
+ hasLocalVariable: (name: string) => boolean;
37
+ addLocalVariable: (name: string) => void;
38
+ removeLocalVariable: (name: string) => void;
39
+ getInternalVariable: () => string;
40
+ ignoreError: () => Generator<Code>;
41
+ expectError: (prevNode: CompilerDOM.CommentNode) => Generator<Code>;
42
+ resetDirectiveComments: (endStr: string) => Generator<Code>;
43
+ generateAutoImportCompletion: () => Generator<Code>;
44
+ };
@@ -0,0 +1,171 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createTemplateCodegenContext = void 0;
4
+ const common_1 = require("../common");
5
+ const _codeFeatures = {
6
+ all: {
7
+ verification: true,
8
+ completion: true,
9
+ semantic: true,
10
+ navigation: true,
11
+ },
12
+ verification: {
13
+ verification: true,
14
+ },
15
+ completion: {
16
+ completion: true,
17
+ },
18
+ additionalCompletion: {
19
+ completion: { isAdditional: true },
20
+ },
21
+ navigation: {
22
+ navigation: true,
23
+ },
24
+ navigationAndCompletion: {
25
+ navigation: true,
26
+ },
27
+ withoutHighlight: {
28
+ semantic: { shouldHighlight: () => false },
29
+ verification: true,
30
+ navigation: true,
31
+ completion: true,
32
+ },
33
+ withoutHighlightAndCompletion: {
34
+ semantic: { shouldHighlight: () => false },
35
+ verification: true,
36
+ navigation: true,
37
+ },
38
+ withoutHighlightAndCompletionAndNavigation: {
39
+ semantic: { shouldHighlight: () => false },
40
+ verification: true,
41
+ },
42
+ };
43
+ function createTemplateCodegenContext() {
44
+ let ignoredError = false;
45
+ let expectErrorToken;
46
+ let variableId = 0;
47
+ const codeFeatures = new Proxy(_codeFeatures, {
48
+ get(target, key) {
49
+ const data = target[key];
50
+ if (data.verification) {
51
+ if (ignoredError) {
52
+ return {
53
+ ...data,
54
+ verification: false,
55
+ };
56
+ }
57
+ if (expectErrorToken) {
58
+ const token = expectErrorToken;
59
+ if (typeof data.verification !== 'object' || !data.verification.shouldReport) {
60
+ return {
61
+ ...data,
62
+ verification: {
63
+ shouldReport: () => {
64
+ token.errors++;
65
+ return false;
66
+ },
67
+ },
68
+ };
69
+ }
70
+ }
71
+ }
72
+ return data;
73
+ },
74
+ });
75
+ const localVars = new Map();
76
+ const accessGlobalVariables = new Map();
77
+ const slots = [];
78
+ const dynamicSlots = [];
79
+ const hasSlotElements = new Set();
80
+ ;
81
+ const blockConditions = [];
82
+ const usedComponentCtxVars = new Set();
83
+ const scopedClasses = [];
84
+ return {
85
+ slots,
86
+ dynamicSlots,
87
+ codeFeatures,
88
+ accessGlobalVariables,
89
+ hasSlotElements,
90
+ blockConditions,
91
+ usedComponentCtxVars,
92
+ scopedClasses,
93
+ accessGlobalVariable(name, offset) {
94
+ let arr = accessGlobalVariables.get(name);
95
+ if (!arr) {
96
+ accessGlobalVariables.set(name, arr = new Set());
97
+ }
98
+ if (offset !== undefined) {
99
+ arr.add(offset);
100
+ }
101
+ },
102
+ hasLocalVariable: (name) => {
103
+ return !!localVars.get(name);
104
+ },
105
+ addLocalVariable: (name) => {
106
+ localVars.set(name, (localVars.get(name) ?? 0) + 1);
107
+ },
108
+ removeLocalVariable: (name) => {
109
+ localVars.set(name, localVars.get(name) - 1);
110
+ },
111
+ getInternalVariable: () => {
112
+ return `__VLS_${variableId++}`;
113
+ },
114
+ ignoreError: function* () {
115
+ if (!ignoredError) {
116
+ ignoredError = true;
117
+ yield `// @vue-ignore start${common_1.newLine}`;
118
+ }
119
+ },
120
+ expectError: function* (prevNode) {
121
+ if (!expectErrorToken) {
122
+ expectErrorToken = {
123
+ errors: 0,
124
+ node: prevNode,
125
+ };
126
+ yield `// @vue-expect-error start${common_1.newLine}`;
127
+ }
128
+ },
129
+ resetDirectiveComments: function* (endStr) {
130
+ if (expectErrorToken) {
131
+ const token = expectErrorToken;
132
+ yield* (0, common_1.wrapWith)(expectErrorToken.node.loc.start.offset, expectErrorToken.node.loc.end.offset, {
133
+ verification: {
134
+ shouldReport: () => token.errors === 0,
135
+ },
136
+ }, `// @ts-expect-error __VLS_TS_EXPECT_ERROR`);
137
+ yield `${common_1.newLine}${common_1.endOfLine}`;
138
+ expectErrorToken = undefined;
139
+ yield `// @vue-expect-error ${endStr}${common_1.newLine}`;
140
+ }
141
+ if (ignoredError) {
142
+ ignoredError = false;
143
+ yield `// @vue-ignore ${endStr}${common_1.newLine}`;
144
+ }
145
+ },
146
+ generateAutoImportCompletion: function* () {
147
+ const all = [...accessGlobalVariables.entries()];
148
+ if (!all.some(([_, offsets]) => offsets.size)) {
149
+ yield `// no auto imports${common_1.endOfLine}`;
150
+ return;
151
+ }
152
+ yield `// @ts-ignore${common_1.newLine}`; // #2304
153
+ yield `[`;
154
+ for (const [varName, offsets] of all) {
155
+ for (const offset of offsets) {
156
+ yield [
157
+ varName,
158
+ 'template',
159
+ offset,
160
+ codeFeatures.additionalCompletion,
161
+ ];
162
+ yield `,`;
163
+ }
164
+ offsets.clear();
165
+ }
166
+ yield `]${common_1.endOfLine}`;
167
+ }
168
+ };
169
+ }
170
+ exports.createTemplateCodegenContext = createTemplateCodegenContext;
171
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1,7 @@
1
+ import * as CompilerDOM from '@vue/compiler-dom';
2
+ import type { Code } from '../../types';
3
+ import type { TemplateCodegenContext } from './context';
4
+ import type { TemplateCodegenOptions } from './index';
5
+ export declare function generateElement(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, currentElement: CompilerDOM.ElementNode | undefined, componentCtxVar: string | undefined): Generator<Code>;
6
+ export declare function getCanonicalComponentName(tagText: string): string;
7
+ export declare function getPossibleOriginalComponentNames(tagText: string, deduplicate: boolean): string[];
@@ -0,0 +1,325 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPossibleOriginalComponentNames = exports.getCanonicalComponentName = exports.generateElement = void 0;
4
+ const CompilerDOM = require("@vue/compiler-dom");
5
+ const shared_1 = require("@vue/shared");
6
+ const common_1 = require("../common");
7
+ const camelized_1 = require("./camelized");
8
+ const elementChildren_1 = require("./elementChildren");
9
+ const elementDirectives_1 = require("./elementDirectives");
10
+ const elementEvents_1 = require("./elementEvents");
11
+ const elementProps_1 = require("./elementProps");
12
+ const interpolation_1 = require("./interpolation");
13
+ const propertyAccess_1 = require("./propertyAccess");
14
+ const stringLiteralKey_1 = require("./stringLiteralKey");
15
+ const templateChild_1 = require("./templateChild");
16
+ const colonReg = /:/g;
17
+ function* generateElement(options, ctx, node, currentElement, componentCtxVar) {
18
+ const startTagOffset = node.loc.start.offset + options.template.content.substring(node.loc.start.offset).indexOf(node.tag);
19
+ const propsFailedExps = [];
20
+ const var_originalComponent = ctx.getInternalVariable();
21
+ const var_functionalComponent = ctx.getInternalVariable();
22
+ const var_componentInstance = ctx.getInternalVariable();
23
+ const var_componentEvents = ctx.getInternalVariable();
24
+ const isIntrinsicElement = node.tagType === CompilerDOM.ElementTypes.ELEMENT
25
+ || node.tagType === CompilerDOM.ElementTypes.TEMPLATE;
26
+ const isComponentTag = node.tag.toLowerCase() === 'component';
27
+ let endTagOffset = !node.isSelfClosing && options.template.lang === 'html' ? node.loc.start.offset + node.loc.source.lastIndexOf(node.tag) : undefined;
28
+ let tag = node.tag;
29
+ let tagOffsets = endTagOffset !== undefined
30
+ ? [startTagOffset, endTagOffset]
31
+ : [startTagOffset];
32
+ let props = node.props;
33
+ let dynamicTagInfo;
34
+ let defineComponentCtxVar;
35
+ let usedComponentEventsVar = false;
36
+ if (isComponentTag) {
37
+ for (const prop of node.props) {
38
+ if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE && prop.name === 'bind' && prop.arg?.loc.source === 'is' && prop.exp) {
39
+ dynamicTagInfo = {
40
+ exp: prop.exp.loc.source,
41
+ offset: prop.exp.loc.start.offset,
42
+ astHolder: prop.exp.loc,
43
+ };
44
+ props = props.filter(p => p !== prop);
45
+ break;
46
+ }
47
+ }
48
+ }
49
+ else if (tag.includes('.')) {
50
+ // namespace tag
51
+ dynamicTagInfo = {
52
+ exp: tag,
53
+ astHolder: node.loc,
54
+ offset: startTagOffset,
55
+ };
56
+ }
57
+ if (isIntrinsicElement) {
58
+ yield `const ${var_originalComponent} = __VLS_intrinsicElements[`;
59
+ yield* (0, stringLiteralKey_1.generateStringLiteralKey)(tag, startTagOffset, ctx.codeFeatures.verification);
60
+ yield `]${common_1.endOfLine}`;
61
+ }
62
+ else if (dynamicTagInfo) {
63
+ yield `const ${var_originalComponent} = `;
64
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, dynamicTagInfo.exp, dynamicTagInfo.astHolder, dynamicTagInfo.offset, ctx.codeFeatures.all, '(', ')');
65
+ yield common_1.endOfLine;
66
+ }
67
+ else if (!isComponentTag) {
68
+ yield `const ${var_originalComponent} = ({} as `;
69
+ for (const componentName of getPossibleOriginalComponentNames(tag, true)) {
70
+ yield `'${componentName}' extends keyof typeof __VLS_ctx ? { '${getCanonicalComponentName(tag)}': typeof __VLS_ctx`;
71
+ yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, componentName);
72
+ yield ` }: `;
73
+ }
74
+ yield `typeof __VLS_resolvedLocalAndGlobalComponents)`;
75
+ yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, getCanonicalComponentName(tag), startTagOffset, ctx.codeFeatures.verification);
76
+ yield common_1.endOfLine;
77
+ }
78
+ else {
79
+ yield `const ${var_originalComponent} = {} as any${common_1.endOfLine}`;
80
+ }
81
+ if (isIntrinsicElement) {
82
+ yield `const ${var_functionalComponent} = __VLS_elementAsFunctionalComponent(${var_originalComponent})${common_1.endOfLine}`;
83
+ }
84
+ else {
85
+ yield `const ${var_functionalComponent} = __VLS_asFunctionalComponent(${var_originalComponent}, new ${var_originalComponent}({`;
86
+ yield* (0, elementProps_1.generateElementProps)(options, ctx, node, props, false);
87
+ yield `}))${common_1.endOfLine}`;
88
+ }
89
+ if (!dynamicTagInfo
90
+ && !isIntrinsicElement
91
+ && !isComponentTag) {
92
+ for (const offset of tagOffsets) {
93
+ yield `({} as { ${getCanonicalComponentName(tag)}: typeof ${var_originalComponent} }).`;
94
+ yield* generateCanonicalComponentName(tag, offset, ctx.codeFeatures.withoutHighlightAndCompletionAndNavigation);
95
+ yield common_1.endOfLine;
96
+ }
97
+ }
98
+ if (options.vueCompilerOptions.strictTemplates) {
99
+ // with strictTemplates, generate once for props type-checking + instance type
100
+ yield `const ${var_componentInstance} = ${var_functionalComponent}(`;
101
+ yield* (0, common_1.wrapWith)(startTagOffset, startTagOffset + tag.length, ctx.codeFeatures.verification, `{`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, props, true, propsFailedExps), `}`);
102
+ yield `, ...__VLS_functionalComponentArgsRest(${var_functionalComponent}))${common_1.endOfLine}`;
103
+ }
104
+ else {
105
+ // without strictTemplates, this only for instacne type
106
+ yield `const ${var_componentInstance} = ${var_functionalComponent}({`;
107
+ yield* (0, elementProps_1.generateElementProps)(options, ctx, node, props, false);
108
+ yield `}, ...__VLS_functionalComponentArgsRest(${var_functionalComponent}))${common_1.endOfLine}`;
109
+ // and this for props type-checking
110
+ yield `({} as (props: __VLS_FunctionalComponentProps<typeof ${var_originalComponent}, typeof ${var_componentInstance}> & Record<string, unknown>) => void)(`;
111
+ yield* (0, common_1.wrapWith)(startTagOffset, startTagOffset + tag.length, ctx.codeFeatures.verification, `{`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, props, true, propsFailedExps), `}`);
112
+ yield `)${common_1.endOfLine}`;
113
+ }
114
+ if (node.tagType !== CompilerDOM.ElementTypes.TEMPLATE) {
115
+ defineComponentCtxVar = ctx.getInternalVariable();
116
+ componentCtxVar = defineComponentCtxVar;
117
+ currentElement = node;
118
+ }
119
+ //#region fix #1775
120
+ for (const failedExp of propsFailedExps) {
121
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, failedExp.loc.source, failedExp.loc, failedExp.loc.start.offset, ctx.codeFeatures.all, '(', ')');
122
+ yield common_1.endOfLine;
123
+ }
124
+ const vScope = props.find(prop => prop.type === CompilerDOM.NodeTypes.DIRECTIVE && (prop.name === 'scope' || prop.name === 'data'));
125
+ let inScope = false;
126
+ let originalConditionsNum = ctx.blockConditions.length;
127
+ if (vScope?.type === CompilerDOM.NodeTypes.DIRECTIVE && vScope.exp) {
128
+ const scopeVar = ctx.getInternalVariable();
129
+ const condition = `__VLS_withScope(__VLS_ctx, ${scopeVar})`;
130
+ yield `const ${scopeVar} = `;
131
+ yield [
132
+ vScope.exp.loc.source,
133
+ 'template',
134
+ vScope.exp.loc.start.offset,
135
+ ctx.codeFeatures.all,
136
+ ];
137
+ yield common_1.endOfLine;
138
+ yield `if (${condition}) {${common_1.newLine}`;
139
+ ctx.blockConditions.push(condition);
140
+ inScope = true;
141
+ }
142
+ yield* (0, elementDirectives_1.generateElementDirectives)(options, ctx, node);
143
+ yield* generateReferencesForElements(options, ctx, node); // <el ref="foo" />
144
+ if (options.shouldGenerateScopedClasses) {
145
+ yield* generateReferencesForScopedCssClasses(ctx, node);
146
+ }
147
+ if (componentCtxVar) {
148
+ ctx.usedComponentCtxVars.add(componentCtxVar);
149
+ yield* (0, elementEvents_1.generateElementEvents)(options, ctx, node, var_functionalComponent, var_componentInstance, var_componentEvents, () => usedComponentEventsVar = true);
150
+ }
151
+ if (inScope) {
152
+ yield `}${common_1.newLine}`;
153
+ ctx.blockConditions.length = originalConditionsNum;
154
+ }
155
+ //#endregion
156
+ const slotDir = node.props.find(p => p.type === CompilerDOM.NodeTypes.DIRECTIVE && p.name === 'slot');
157
+ if (slotDir && componentCtxVar) {
158
+ yield* generateComponentSlot(options, ctx, node, slotDir, currentElement, componentCtxVar);
159
+ }
160
+ else {
161
+ yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node, currentElement, componentCtxVar);
162
+ }
163
+ if (defineComponentCtxVar && ctx.usedComponentCtxVars.has(defineComponentCtxVar)) {
164
+ yield `const ${componentCtxVar} = __VLS_pickFunctionalComponentCtx(${var_originalComponent}, ${var_componentInstance})!${common_1.endOfLine}`;
165
+ }
166
+ if (usedComponentEventsVar) {
167
+ yield `let ${var_componentEvents}!: __VLS_NormalizeEmits<typeof ${componentCtxVar}.emit>${common_1.endOfLine}`;
168
+ }
169
+ }
170
+ exports.generateElement = generateElement;
171
+ function getCanonicalComponentName(tagText) {
172
+ return common_1.variableNameRegex.test(tagText)
173
+ ? tagText
174
+ : (0, shared_1.capitalize)((0, shared_1.camelize)(tagText.replace(colonReg, '-')));
175
+ }
176
+ exports.getCanonicalComponentName = getCanonicalComponentName;
177
+ function getPossibleOriginalComponentNames(tagText, deduplicate) {
178
+ const name1 = (0, shared_1.capitalize)((0, shared_1.camelize)(tagText));
179
+ const name2 = (0, shared_1.camelize)(tagText);
180
+ const name3 = tagText;
181
+ const names = [name1];
182
+ if (!deduplicate || name2 !== name1) {
183
+ names.push(name2);
184
+ }
185
+ if (!deduplicate || name3 !== name2) {
186
+ names.push(name3);
187
+ }
188
+ return names;
189
+ }
190
+ exports.getPossibleOriginalComponentNames = getPossibleOriginalComponentNames;
191
+ function* generateCanonicalComponentName(tagText, offset, features) {
192
+ if (common_1.variableNameRegex.test(tagText)) {
193
+ yield [tagText, 'template', offset, features];
194
+ }
195
+ else {
196
+ yield* (0, camelized_1.generateCamelized)((0, shared_1.capitalize)(tagText.replace(colonReg, '-')), offset, features);
197
+ }
198
+ }
199
+ function* generateComponentSlot(options, ctx, node, slotDir, currentElement, componentCtxVar) {
200
+ yield `{${common_1.newLine}`;
201
+ ctx.usedComponentCtxVars.add(componentCtxVar);
202
+ if (currentElement) {
203
+ ctx.hasSlotElements.add(currentElement);
204
+ }
205
+ const slotBlockVars = [];
206
+ let hasProps = false;
207
+ if (slotDir?.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
208
+ const slotAst = (0, common_1.createTsAst)(options.ts, slotDir, `(${slotDir.exp.content}) => {}`);
209
+ (0, common_1.collectVars)(options.ts, slotAst, slotAst, slotBlockVars);
210
+ hasProps = true;
211
+ if (!slotDir.exp.content.includes(':')) {
212
+ yield `const [`;
213
+ yield [
214
+ slotDir.exp.content,
215
+ 'template',
216
+ slotDir.exp.loc.start.offset,
217
+ ctx.codeFeatures.all,
218
+ ];
219
+ yield `] = __VLS_getSlotParams(`;
220
+ }
221
+ else {
222
+ yield `const `;
223
+ yield [
224
+ slotDir.exp.content,
225
+ 'template',
226
+ slotDir.exp.loc.start.offset,
227
+ ctx.codeFeatures.all,
228
+ ];
229
+ yield ` = __VLS_getSlotParam(`;
230
+ }
231
+ }
232
+ yield* (0, common_1.wrapWith)((slotDir.arg ?? slotDir).loc.start.offset, (slotDir.arg ?? slotDir).loc.end.offset, ctx.codeFeatures.verification, `(${componentCtxVar}.slots!)`, ...(slotDir?.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && slotDir.arg.content
233
+ ? (0, propertyAccess_1.generatePropertyAccess)(options, ctx, slotDir.arg.loc.source, slotDir.arg.loc.start.offset, slotDir.arg.isStatic ? ctx.codeFeatures.withoutHighlight : ctx.codeFeatures.all, slotDir.arg.loc)
234
+ : [
235
+ `.`,
236
+ ...(0, common_1.wrapWith)(slotDir.loc.start.offset, slotDir.loc.start.offset + (slotDir.loc.source.startsWith('#')
237
+ ? '#'.length
238
+ : slotDir.loc.source.startsWith('v-slot:')
239
+ ? 'v-slot:'.length
240
+ : 0), ctx.codeFeatures.withoutHighlightAndCompletion, `default`)
241
+ ]));
242
+ if (hasProps) {
243
+ yield `)`;
244
+ }
245
+ yield common_1.endOfLine;
246
+ for (const varName of slotBlockVars) {
247
+ ctx.addLocalVariable(varName);
248
+ }
249
+ yield* ctx.resetDirectiveComments('end of slot children start');
250
+ let prev;
251
+ for (const childNode of node.children) {
252
+ yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, currentElement, prev, componentCtxVar);
253
+ prev = childNode;
254
+ }
255
+ for (const varName of slotBlockVars) {
256
+ ctx.removeLocalVariable(varName);
257
+ }
258
+ let isStatic = true;
259
+ if (slotDir?.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
260
+ isStatic = slotDir.arg.isStatic;
261
+ }
262
+ if (isStatic && slotDir && !slotDir.arg) {
263
+ yield `${componentCtxVar}.slots!['`;
264
+ yield [
265
+ '',
266
+ 'template',
267
+ slotDir.loc.start.offset + (slotDir.loc.source.startsWith('#')
268
+ ? '#'.length : slotDir.loc.source.startsWith('v-slot:')
269
+ ? 'v-slot:'.length
270
+ : 0),
271
+ ctx.codeFeatures.completion,
272
+ ];
273
+ yield `'/* empty slot name completion */]${common_1.newLine}`;
274
+ }
275
+ yield* ctx.generateAutoImportCompletion();
276
+ yield `}${common_1.newLine}`;
277
+ }
278
+ function* generateReferencesForElements(options, ctx, node) {
279
+ for (const prop of node.props) {
280
+ if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE
281
+ && prop.name === 'ref'
282
+ && prop.value) {
283
+ yield `// @ts-ignore${common_1.newLine}`;
284
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, prop.value.content, prop.value.loc, prop.value.loc.start.offset + 1, ctx.codeFeatures.navigation, '(', ')');
285
+ yield common_1.endOfLine;
286
+ }
287
+ }
288
+ }
289
+ function* generateReferencesForScopedCssClasses(ctx, node) {
290
+ for (const prop of node.props) {
291
+ if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE
292
+ && prop.name === 'class'
293
+ && prop.value) {
294
+ let startOffset = prop.value.loc.start.offset;
295
+ let tempClassName = '';
296
+ for (const char of (prop.value.loc.source + ' ')) {
297
+ if (char.trim() === '' || char === '"' || char === "'") {
298
+ if (tempClassName !== '') {
299
+ ctx.scopedClasses.push({ className: tempClassName, offset: startOffset });
300
+ startOffset += tempClassName.length;
301
+ tempClassName = '';
302
+ }
303
+ startOffset += char.length;
304
+ }
305
+ else {
306
+ tempClassName += char;
307
+ }
308
+ }
309
+ }
310
+ else if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
311
+ && prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
312
+ && prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
313
+ && prop.arg.content === 'class') {
314
+ yield `__VLS_styleScopedClasses = (`;
315
+ yield [
316
+ prop.exp.content,
317
+ 'template',
318
+ prop.exp.loc.start.offset,
319
+ ctx.codeFeatures.navigationAndCompletion,
320
+ ];
321
+ yield `)${common_1.endOfLine}`;
322
+ }
323
+ }
324
+ }
325
+ //# sourceMappingURL=element.js.map
@@ -0,0 +1,5 @@
1
+ import type * as CompilerDOM from '@vue/compiler-dom';
2
+ import type { Code } from '../../types';
3
+ import type { TemplateCodegenContext } from './context';
4
+ import type { TemplateCodegenOptions } from './index';
5
+ export declare function generateElementChildren(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, currentElement: CompilerDOM.ElementNode | undefined, componentCtxVar: string | undefined): Generator<Code>;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateElementChildren = void 0;
4
+ const common_1 = require("../common");
5
+ const templateChild_1 = require("./templateChild");
6
+ function* generateElementChildren(options, ctx, node, currentElement, componentCtxVar) {
7
+ yield* ctx.resetDirectiveComments('end of element children start');
8
+ let prev;
9
+ for (const childNode of node.children) {
10
+ yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, currentElement, prev, componentCtxVar);
11
+ prev = childNode;
12
+ }
13
+ // fix https://github.com/vuejs/language-tools/issues/932
14
+ if (!ctx.hasSlotElements.has(node) && node.children.length) {
15
+ yield `(${componentCtxVar}.slots!).`;
16
+ yield* (0, common_1.wrapWith)(node.children[0].loc.start.offset, node.children[node.children.length - 1].loc.end.offset, ctx.codeFeatures.navigation, `default`);
17
+ yield common_1.endOfLine;
18
+ }
19
+ }
20
+ exports.generateElementChildren = generateElementChildren;
21
+ //# sourceMappingURL=elementChildren.js.map
@@ -0,0 +1,5 @@
1
+ import * as CompilerDOM from '@vue/compiler-dom';
2
+ import type { Code } from '../../types';
3
+ import type { TemplateCodegenContext } from './context';
4
+ import type { TemplateCodegenOptions } from './index';
5
+ export declare function generateElementDirectives(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode): Generator<Code>;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateElementDirectives = void 0;
4
+ const CompilerDOM = require("@vue/compiler-dom");
5
+ const shared_1 = require("@vue/shared");
6
+ const shared_2 = require("../../utils/shared");
7
+ const common_1 = require("../common");
8
+ const camelized_1 = require("./camelized");
9
+ const interpolation_1 = require("./interpolation");
10
+ function* generateElementDirectives(options, ctx, node) {
11
+ for (const prop of node.props) {
12
+ if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
13
+ && prop.name !== 'slot'
14
+ && prop.name !== 'on'
15
+ && prop.name !== 'model'
16
+ && prop.name !== 'bind'
17
+ && prop.name !== 'scope'
18
+ && prop.name !== 'data') {
19
+ ctx.accessGlobalVariable((0, shared_1.camelize)('v-' + prop.name), prop.loc.start.offset);
20
+ if (prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && !prop.arg.isStatic) {
21
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, prop.arg.content, prop.arg.loc, prop.arg.loc.start.offset + prop.arg.loc.source.indexOf(prop.arg.content), ctx.codeFeatures.all, '(', ')');
22
+ yield common_1.endOfLine;
23
+ }
24
+ yield* (0, common_1.wrapWith)(prop.loc.start.offset, prop.loc.end.offset, ctx.codeFeatures.verification, `__VLS_directiveFunction(__VLS_ctx.`, ...(0, camelized_1.generateCamelized)('v-' + prop.name, prop.loc.start.offset, {
25
+ ...ctx.codeFeatures.all,
26
+ verification: false,
27
+ completion: {
28
+ // fix https://github.com/vuejs/language-tools/issues/1905
29
+ isAdditional: true,
30
+ },
31
+ navigation: {
32
+ resolveRenameNewName: shared_1.camelize,
33
+ resolveRenameEditText: getPropRenameApply(prop.name),
34
+ },
35
+ }), `)(`, ...(prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
36
+ ? (0, common_1.wrapWith)(prop.exp.loc.start.offset, prop.exp.loc.end.offset, ctx.codeFeatures.verification, ...(0, interpolation_1.generateInterpolation)(options, ctx, prop.exp.content, prop.exp.loc, prop.exp.loc.start.offset, ctx.codeFeatures.all, '(', ')'))
37
+ : [`undefined`]), `)`);
38
+ yield common_1.endOfLine;
39
+ }
40
+ }
41
+ }
42
+ exports.generateElementDirectives = generateElementDirectives;
43
+ function getPropRenameApply(oldName) {
44
+ return oldName === (0, shared_2.hyphenateAttr)(oldName) ? shared_2.hyphenateAttr : undefined;
45
+ }
46
+ //# sourceMappingURL=elementDirectives.js.map
@@ -0,0 +1,7 @@
1
+ import * as CompilerDOM from '@vue/compiler-dom';
2
+ import type * as ts from 'typescript';
3
+ import type { Code } from '../../types';
4
+ import type { TemplateCodegenContext } from './context';
5
+ import type { TemplateCodegenOptions } from './index';
6
+ export declare function generateElementEvents(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, componentVar: string, componentInstanceVar: string, eventsVar: string, used: () => void): Generator<Code>;
7
+ export declare function isCompoundExpression(ts: typeof import('typescript'), ast: ts.SourceFile): boolean;