@vue/language-core 2.0.13 → 2.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/lib/codegen/common.d.ts +11 -0
- package/lib/codegen/common.js +70 -0
- package/lib/codegen/script/component.d.ts +9 -0
- package/lib/codegen/script/component.js +109 -0
- package/lib/codegen/script/context.d.ts +25 -0
- package/lib/codegen/script/context.js +124 -0
- package/lib/{generators → codegen/script}/globalTypes.d.ts +1 -1
- package/lib/codegen/script/globalTypes.js +135 -0
- package/lib/codegen/script/index.d.ts +33 -0
- package/lib/codegen/script/index.js +127 -0
- package/lib/codegen/script/internalComponent.d.ts +5 -0
- package/lib/codegen/script/internalComponent.js +58 -0
- package/lib/codegen/script/scriptSetup.d.ts +6 -0
- package/lib/codegen/script/scriptSetup.js +371 -0
- package/lib/codegen/script/src.d.ts +2 -0
- package/lib/codegen/script/src.js +52 -0
- package/lib/codegen/script/template.d.ts +5 -0
- package/lib/codegen/script/template.js +196 -0
- package/lib/codegen/template/camelized.d.ts +2 -0
- package/lib/codegen/template/camelized.js +32 -0
- package/lib/codegen/template/context.d.ts +44 -0
- package/lib/codegen/template/context.js +170 -0
- package/lib/codegen/template/element.d.ts +8 -0
- package/lib/codegen/template/element.js +378 -0
- package/lib/codegen/template/elementChildren.d.ts +5 -0
- package/lib/codegen/template/elementChildren.js +26 -0
- package/lib/codegen/template/elementDirectives.d.ts +5 -0
- package/lib/codegen/template/elementDirectives.js +46 -0
- package/lib/codegen/template/elementEvents.d.ts +9 -0
- package/lib/codegen/template/elementEvents.js +157 -0
- package/lib/codegen/template/elementProps.d.ts +5 -0
- package/lib/codegen/template/elementProps.js +275 -0
- package/lib/codegen/template/index.d.ts +60 -0
- package/lib/codegen/template/index.js +130 -0
- package/lib/codegen/template/interpolation.d.ts +6 -0
- package/lib/{utils/transform.js → codegen/template/interpolation.js} +76 -46
- package/lib/codegen/template/objectProperty.d.ts +4 -0
- package/lib/codegen/template/objectProperty.js +31 -0
- package/lib/codegen/template/propertyAccess.d.ts +4 -0
- package/lib/codegen/template/propertyAccess.js +24 -0
- package/lib/codegen/template/slotOutlet.d.ts +5 -0
- package/lib/codegen/template/slotOutlet.js +72 -0
- package/lib/codegen/template/stringLiteralKey.d.ts +2 -0
- package/lib/codegen/template/stringLiteralKey.js +14 -0
- package/lib/codegen/template/templateChild.d.ts +7 -0
- package/lib/codegen/template/templateChild.js +160 -0
- package/lib/codegen/template/vFor.d.ts +12 -0
- package/lib/codegen/template/vFor.js +69 -0
- package/lib/codegen/template/vIf.d.ts +5 -0
- package/lib/codegen/template/vIf.js +53 -0
- package/lib/languageModule.d.ts +3 -4
- package/lib/languageModule.js +31 -14
- package/lib/parsers/scriptSetupRanges.d.ts +1 -0
- package/lib/parsers/scriptSetupRanges.js +6 -1
- package/lib/plugins/file-html.js +63 -66
- package/lib/plugins/file-md.js +47 -50
- package/lib/plugins/shared.d.ts +2 -0
- package/lib/plugins/shared.js +12 -0
- package/lib/plugins/vue-sfc-customblocks.js +2 -2
- package/lib/plugins/vue-sfc-scripts.js +2 -3
- package/lib/plugins/vue-sfc-styles.js +3 -3
- package/lib/plugins/vue-sfc-template.js +2 -2
- package/lib/plugins/vue-template-inline-css.js +34 -2
- package/lib/plugins/vue-template-inline-ts.js +10 -8
- package/lib/plugins/vue-tsx.d.ts +43 -5
- package/lib/plugins/vue-tsx.js +38 -28
- package/lib/plugins.d.ts +2 -1
- package/lib/plugins.js +18 -9
- package/lib/types.d.ts +3 -3
- package/lib/utils/ts.js +20 -32
- package/lib/virtualFile/computedFiles.d.ts +2 -1
- package/lib/virtualFile/computedFiles.js +41 -15
- package/lib/virtualFile/computedMappings.js +3 -3
- package/lib/virtualFile/computedSfc.js +22 -1
- package/lib/virtualFile/embeddedFile.d.ts +2 -3
- package/lib/virtualFile/embeddedFile.js +1 -2
- package/lib/virtualFile/vueFile.d.ts +3 -5
- package/lib/virtualFile/vueFile.js +6 -8
- package/package.json +3 -3
- package/lib/generators/globalTypes.js +0 -135
- package/lib/generators/inlineCss.d.ts +0 -3
- package/lib/generators/inlineCss.js +0 -37
- package/lib/generators/script.d.ts +0 -13
- package/lib/generators/script.js +0 -981
- package/lib/generators/template.d.ts +0 -19
- package/lib/generators/template.js +0 -1578
- package/lib/generators/utils.d.ts +0 -5
- package/lib/generators/utils.js +0 -54
- package/lib/utils/transform.d.ts +0 -8
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTemplateUsageVars = exports.generateTemplate = void 0;
|
|
4
|
+
const shared_1 = require("../../utils/shared");
|
|
5
|
+
const common_1 = require("../common");
|
|
6
|
+
const context_1 = require("../template/context");
|
|
7
|
+
const interpolation_1 = require("../template/interpolation");
|
|
8
|
+
const index_1 = require("./index");
|
|
9
|
+
const internalComponent_1 = require("./internalComponent");
|
|
10
|
+
const common_2 = require("../common");
|
|
11
|
+
function* generateTemplate(options, ctx) {
|
|
12
|
+
ctx.generatedTemplate = true;
|
|
13
|
+
if (!options.vueCompilerOptions.skipTemplateCodegen) {
|
|
14
|
+
yield* generateExportOptions(options);
|
|
15
|
+
yield* generateConstNameOption(options);
|
|
16
|
+
yield `function __VLS_template() {${common_1.newLine}`;
|
|
17
|
+
const templateCodegenCtx = (0, context_1.createTemplateCodegenContext)();
|
|
18
|
+
yield* generateTemplateContext(options, ctx, templateCodegenCtx);
|
|
19
|
+
yield `}${common_1.newLine}`;
|
|
20
|
+
yield* (0, internalComponent_1.generateInternalComponent)(options, ctx, templateCodegenCtx);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
yield `function __VLS_template() {${common_1.newLine}`;
|
|
24
|
+
const templateUsageVars = [...getTemplateUsageVars(options, ctx)];
|
|
25
|
+
yield `// @ts-ignore${common_1.newLine}`;
|
|
26
|
+
yield `[${templateUsageVars.join(', ')}]${common_1.newLine}`;
|
|
27
|
+
yield `return {}${common_1.endOfLine}`;
|
|
28
|
+
yield `}${common_1.newLine}`;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.generateTemplate = generateTemplate;
|
|
32
|
+
function* generateExportOptions(options) {
|
|
33
|
+
yield common_1.newLine;
|
|
34
|
+
yield `const __VLS_componentsOption = `;
|
|
35
|
+
if (options.sfc.script && options.scriptRanges?.exportDefault?.componentsOption) {
|
|
36
|
+
const componentsOption = options.scriptRanges.exportDefault.componentsOption;
|
|
37
|
+
yield [
|
|
38
|
+
options.sfc.script.content.substring(componentsOption.start, componentsOption.end),
|
|
39
|
+
'script',
|
|
40
|
+
componentsOption.start,
|
|
41
|
+
index_1.codeFeatures.navigation,
|
|
42
|
+
];
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
yield `{}`;
|
|
46
|
+
}
|
|
47
|
+
yield common_1.endOfLine;
|
|
48
|
+
}
|
|
49
|
+
function* generateConstNameOption(options) {
|
|
50
|
+
yield common_1.newLine;
|
|
51
|
+
if (options.sfc.script && options.scriptRanges?.exportDefault?.nameOption) {
|
|
52
|
+
const nameOption = options.scriptRanges.exportDefault.nameOption;
|
|
53
|
+
yield `const __VLS_name = `;
|
|
54
|
+
yield `${options.sfc.script.content.substring(nameOption.start, nameOption.end)} as const`;
|
|
55
|
+
yield common_1.endOfLine;
|
|
56
|
+
}
|
|
57
|
+
else if (options.sfc.scriptSetup) {
|
|
58
|
+
yield `let __VLS_name!: '${options.fileBaseName.substring(0, options.fileBaseName.lastIndexOf('.'))}'${common_1.endOfLine}`;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
yield `const __VLS_name = undefined${common_1.endOfLine}`;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function* generateTemplateContext(options, ctx, templateCodegenCtx) {
|
|
65
|
+
const useGlobalThisTypeInCtx = options.fileBaseName.endsWith('.html');
|
|
66
|
+
yield `let __VLS_ctx!: ${useGlobalThisTypeInCtx ? 'typeof globalThis &' : ''}`;
|
|
67
|
+
yield `InstanceType<__VLS_PickNotAny<typeof __VLS_internalComponent, new () => {}>> & {${common_1.newLine}`;
|
|
68
|
+
/* CSS Module */
|
|
69
|
+
for (let i = 0; i < options.sfc.styles.length; i++) {
|
|
70
|
+
const style = options.sfc.styles[i];
|
|
71
|
+
if (style.module) {
|
|
72
|
+
yield `${style.module}: Record<string, string> & ${ctx.helperTypes.Prettify.name}<{}`;
|
|
73
|
+
for (const className of style.classNames) {
|
|
74
|
+
yield* generateCssClassProperty(i, className.text, className.offset, 'string', false, true);
|
|
75
|
+
}
|
|
76
|
+
yield `>${common_1.endOfLine}`;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
yield `}${common_1.endOfLine}`;
|
|
80
|
+
/* Components */
|
|
81
|
+
yield `/* Components */${common_1.newLine}`;
|
|
82
|
+
yield `let __VLS_otherComponents!: NonNullable<typeof __VLS_internalComponent extends { components: infer C } ? C : {}> & typeof __VLS_componentsOption${common_1.endOfLine}`;
|
|
83
|
+
yield `let __VLS_own!: __VLS_SelfComponent<typeof __VLS_name, typeof __VLS_internalComponent & (new () => { ${(0, shared_1.getSlotsPropertyName)(options.vueCompilerOptions.target)}: typeof ${options.scriptSetupRanges?.slots?.name ?? '__VLS_slots'} })>${common_1.endOfLine}`;
|
|
84
|
+
yield `let __VLS_localComponents!: typeof __VLS_otherComponents & Omit<typeof __VLS_own, keyof typeof __VLS_otherComponents>${common_1.endOfLine}`;
|
|
85
|
+
yield `let __VLS_components!: typeof __VLS_localComponents & __VLS_GlobalComponents & typeof __VLS_ctx${common_1.endOfLine}`; // for html completion, TS references...
|
|
86
|
+
/* Style Scoped */
|
|
87
|
+
yield `/* Style Scoped */${common_1.newLine}`;
|
|
88
|
+
yield `type __VLS_StyleScopedClasses = {}`;
|
|
89
|
+
for (let i = 0; i < options.sfc.styles.length; i++) {
|
|
90
|
+
const style = options.sfc.styles[i];
|
|
91
|
+
const option = options.vueCompilerOptions.experimentalResolveStyleCssClasses;
|
|
92
|
+
if (option === 'always' || (option === 'scoped' && style.scoped)) {
|
|
93
|
+
for (const className of style.classNames) {
|
|
94
|
+
yield* generateCssClassProperty(i, className.text, className.offset, 'boolean', true, !style.module);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
yield common_1.endOfLine;
|
|
99
|
+
yield `let __VLS_styleScopedClasses!: __VLS_StyleScopedClasses | keyof __VLS_StyleScopedClasses | (keyof __VLS_StyleScopedClasses)[]${common_1.endOfLine}`;
|
|
100
|
+
yield* generateCssVars(options, templateCodegenCtx);
|
|
101
|
+
if (options.templateCodegen) {
|
|
102
|
+
for (const code of options.templateCodegen.tsCodes) {
|
|
103
|
+
yield code;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
yield `// no template${common_1.newLine}`;
|
|
108
|
+
if (!options.scriptSetupRanges?.slots.define) {
|
|
109
|
+
yield `const __VLS_slots = {}${common_1.endOfLine}`;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
yield `return ${options.scriptSetupRanges?.slots.name ?? '__VLS_slots'}${common_1.endOfLine}`;
|
|
113
|
+
}
|
|
114
|
+
function* generateCssClassProperty(styleIndex, classNameWithDot, offset, propertyType, optional, referencesCodeLens) {
|
|
115
|
+
yield `${common_1.newLine} & { `;
|
|
116
|
+
yield [
|
|
117
|
+
'',
|
|
118
|
+
'style_' + styleIndex,
|
|
119
|
+
offset,
|
|
120
|
+
referencesCodeLens
|
|
121
|
+
? index_1.codeFeatures.navigation
|
|
122
|
+
: index_1.codeFeatures.referencesCodeLens,
|
|
123
|
+
];
|
|
124
|
+
yield `'`;
|
|
125
|
+
yield [
|
|
126
|
+
'',
|
|
127
|
+
'style_' + styleIndex,
|
|
128
|
+
offset,
|
|
129
|
+
index_1.codeFeatures.cssClassNavigation,
|
|
130
|
+
];
|
|
131
|
+
yield [
|
|
132
|
+
classNameWithDot.substring(1),
|
|
133
|
+
'style_' + styleIndex,
|
|
134
|
+
offset + 1,
|
|
135
|
+
common_2.combineLastMapping,
|
|
136
|
+
];
|
|
137
|
+
yield `'`;
|
|
138
|
+
yield [
|
|
139
|
+
'',
|
|
140
|
+
'style_' + styleIndex,
|
|
141
|
+
offset + classNameWithDot.length,
|
|
142
|
+
index_1.codeFeatures.none,
|
|
143
|
+
];
|
|
144
|
+
yield `${optional ? '?' : ''}: ${propertyType}`;
|
|
145
|
+
yield ` }`;
|
|
146
|
+
}
|
|
147
|
+
function* generateCssVars(options, ctx) {
|
|
148
|
+
if (!options.sfc.styles.length) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
yield `// CSS variable injection ${common_1.newLine}`;
|
|
152
|
+
for (const style of options.sfc.styles) {
|
|
153
|
+
for (const cssBind of style.cssVars) {
|
|
154
|
+
for (const [segment, offset, onlyError] of (0, interpolation_1.forEachInterpolationSegment)(options.ts, options.vueCompilerOptions, ctx, cssBind.text, cssBind.offset, options.ts.createSourceFile('/a.txt', cssBind.text, 99))) {
|
|
155
|
+
if (offset === undefined) {
|
|
156
|
+
yield segment;
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
yield [
|
|
160
|
+
segment,
|
|
161
|
+
style.name,
|
|
162
|
+
cssBind.offset + offset,
|
|
163
|
+
onlyError
|
|
164
|
+
? index_1.codeFeatures.navigation
|
|
165
|
+
: index_1.codeFeatures.all,
|
|
166
|
+
];
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
yield common_1.endOfLine;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
yield `// CSS variable injection end ${common_1.newLine}`;
|
|
173
|
+
}
|
|
174
|
+
function getTemplateUsageVars(options, ctx) {
|
|
175
|
+
const usageVars = new Set();
|
|
176
|
+
const components = new Set(options.sfc.template?.ast?.components);
|
|
177
|
+
if (options.templateCodegen) {
|
|
178
|
+
// fix import components unused report
|
|
179
|
+
for (const varName of ctx.bindingNames) {
|
|
180
|
+
if (components.has(varName) || components.has((0, shared_1.hyphenateTag)(varName))) {
|
|
181
|
+
usageVars.add(varName);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
for (const component of components) {
|
|
185
|
+
if (component.indexOf('.') >= 0) {
|
|
186
|
+
usageVars.add(component.split('.')[0]);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
for (const [varName] of options.templateCodegen.ctx.accessGlobalVariables) {
|
|
190
|
+
usageVars.add(varName);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return usageVars;
|
|
194
|
+
}
|
|
195
|
+
exports.getTemplateUsageVars = getTemplateUsageVars;
|
|
196
|
+
//# sourceMappingURL=template.js.map
|
|
@@ -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,170 @@
|
|
|
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
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
yield `// @ts-ignore${common_1.newLine}`; // #2304
|
|
152
|
+
yield `[`;
|
|
153
|
+
for (const [varName, offsets] of all) {
|
|
154
|
+
for (const offset of offsets) {
|
|
155
|
+
yield [
|
|
156
|
+
varName,
|
|
157
|
+
'template',
|
|
158
|
+
offset,
|
|
159
|
+
codeFeatures.additionalCompletion,
|
|
160
|
+
];
|
|
161
|
+
yield `,`;
|
|
162
|
+
}
|
|
163
|
+
offsets.clear();
|
|
164
|
+
}
|
|
165
|
+
yield `]${common_1.endOfLine}`;
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
exports.createTemplateCodegenContext = createTemplateCodegenContext;
|
|
170
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
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 generateComponent(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, currentComponent: CompilerDOM.ElementNode | undefined, componentCtxVar: string | undefined): Generator<Code>;
|
|
6
|
+
export declare function generateElement(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, currentComponent: CompilerDOM.ElementNode | undefined, componentCtxVar: string | undefined): Generator<Code>;
|
|
7
|
+
export declare function getCanonicalComponentName(tagText: string): string;
|
|
8
|
+
export declare function getPossibleOriginalComponentNames(tagText: string, deduplicate: boolean): string[];
|