@vue/language-core 2.1.4 → 2.1.6-patch.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.
- package/lib/codegen/common.d.ts +2 -2
- package/lib/codegen/common.js +8 -10
- package/lib/codegen/globalTypes.d.ts +1 -1
- package/lib/codegen/globalTypes.js +123 -125
- package/lib/codegen/script/component.js +38 -32
- package/lib/codegen/script/{internalComponent.d.ts → componentSelf.d.ts} +1 -1
- package/lib/codegen/script/{internalComponent.js → componentSelf.js} +6 -6
- package/lib/codegen/script/index.d.ts +1 -0
- package/lib/codegen/script/index.js +14 -6
- package/lib/codegen/script/scriptSetup.js +10 -37
- package/lib/codegen/script/styleModulesType.d.ts +4 -0
- package/lib/codegen/script/styleModulesType.js +36 -0
- package/lib/codegen/script/template.d.ts +3 -3
- package/lib/codegen/script/template.js +56 -67
- package/lib/codegen/template/context.d.ts +2 -0
- package/lib/codegen/template/context.js +3 -0
- package/lib/codegen/template/element.js +15 -6
- package/lib/codegen/template/elementDirectives.js +1 -1
- package/lib/codegen/template/elementEvents.js +4 -1
- package/lib/codegen/template/elementProps.js +28 -19
- package/lib/codegen/template/index.d.ts +3 -2
- package/lib/codegen/template/index.js +63 -53
- package/lib/codegen/template/interpolation.d.ts +1 -1
- package/lib/codegen/template/interpolation.js +52 -26
- package/lib/codegen/template/templateChild.js +4 -0
- package/lib/parsers/scriptRanges.d.ts +1 -0
- package/lib/parsers/scriptRanges.js +7 -2
- package/lib/parsers/scriptSetupRanges.d.ts +2 -1
- package/lib/parsers/scriptSetupRanges.js +12 -2
- package/lib/plugins/vue-sfc-template.js +2 -2
- package/lib/plugins/vue-tsx.d.ts +5 -1
- package/lib/plugins/vue-tsx.js +37 -10
- package/lib/types.d.ts +2 -2
- package/lib/utils/ts.d.ts +8 -2
- package/lib/utils/ts.js +45 -8
- package/package.json +5 -6
- package/lib/codegen/script/globalTypes.d.ts +0 -2
- package/lib/codegen/script/globalTypes.js +0 -147
- package/lib/codegen/template/vBindShorthand.d.ts +0 -3
- package/lib/codegen/template/vBindShorthand.js +0 -18
|
@@ -5,6 +5,7 @@ exports.generateScriptSetup = generateScriptSetup;
|
|
|
5
5
|
const common_1 = require("../common");
|
|
6
6
|
const component_1 = require("./component");
|
|
7
7
|
const index_1 = require("./index");
|
|
8
|
+
const componentSelf_1 = require("./componentSelf");
|
|
8
9
|
const template_1 = require("./template");
|
|
9
10
|
function* generateScriptSetupImports(scriptSetup, scriptSetupRanges) {
|
|
10
11
|
yield [
|
|
@@ -57,7 +58,7 @@ function* generateScriptSetup(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
|
57
58
|
+ ` props: ${ctx.localTypes.PrettifyLocal}<typeof __VLS_functionalComponentProps & __VLS_PublicProps> & __VLS_BuiltInPublicProps,${common_1.newLine}`
|
|
58
59
|
+ ` expose(exposed: import('${options.vueCompilerOptions.lib}').ShallowUnwrapRef<${scriptSetupRanges.expose.define ? 'typeof __VLS_exposed' : '{}'}>): void,${common_1.newLine}`
|
|
59
60
|
+ ` attrs: any,${common_1.newLine}`
|
|
60
|
-
+ ` slots:
|
|
61
|
+
+ ` slots: __VLS_TemplateResult['slots'],${common_1.newLine}`
|
|
61
62
|
+ ` emit: ${emitTypes.length ? emitTypes.join(' & ') : `{}`},${common_1.newLine}`
|
|
62
63
|
+ ` }${common_1.endOfLine}`;
|
|
63
64
|
yield ` })(),${common_1.newLine}`; // __VLS_setup = (async () => {
|
|
@@ -223,9 +224,9 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
|
|
|
223
224
|
if (define?.arg) {
|
|
224
225
|
setupCodeModifies.push([
|
|
225
226
|
[
|
|
226
|
-
`<
|
|
227
|
+
`<__VLS_TemplateResult['refs'][`,
|
|
227
228
|
(0, common_1.generateSfcBlockSection)(scriptSetup, define.arg.start, define.arg.end, index_1.codeFeatures.navigation),
|
|
228
|
-
`], keyof
|
|
229
|
+
`], keyof __VLS_TemplateResult['refs']>`
|
|
229
230
|
],
|
|
230
231
|
define.arg.start - 1,
|
|
231
232
|
define.arg.start - 1
|
|
@@ -260,17 +261,18 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
|
|
|
260
261
|
}
|
|
261
262
|
yield* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges, definePropMirrors);
|
|
262
263
|
yield* generateModelEmits(options, scriptSetup, scriptSetupRanges);
|
|
263
|
-
yield
|
|
264
|
-
yield* (0, template_1.generateTemplate)(options, ctx, false);
|
|
265
|
-
yield `
|
|
266
|
-
yield
|
|
264
|
+
yield `function __VLS_template() {${common_1.newLine}`;
|
|
265
|
+
const templateCodegenCtx = yield* (0, template_1.generateTemplate)(options, ctx, false);
|
|
266
|
+
yield `}${common_1.endOfLine}`;
|
|
267
|
+
yield* (0, componentSelf_1.generateComponentSelf)(options, ctx, templateCodegenCtx);
|
|
268
|
+
yield `type __VLS_TemplateResult = ReturnType<typeof __VLS_template>${common_1.endOfLine}`;
|
|
267
269
|
if (syntax) {
|
|
268
270
|
if (!options.vueCompilerOptions.skipTemplateCodegen && (options.templateCodegen?.hasSlot || scriptSetupRanges?.slots.define)) {
|
|
269
271
|
yield `const __VLS_component = `;
|
|
270
272
|
yield* (0, component_1.generateComponent)(options, ctx, scriptSetup, scriptSetupRanges);
|
|
271
273
|
yield common_1.endOfLine;
|
|
272
274
|
yield `${syntax} `;
|
|
273
|
-
yield `{} as ${ctx.localTypes.WithTemplateSlots}<typeof __VLS_component,
|
|
275
|
+
yield `{} as ${ctx.localTypes.WithTemplateSlots}<typeof __VLS_component, __VLS_TemplateResult['slots']>${common_1.endOfLine}`;
|
|
274
276
|
}
|
|
275
277
|
else {
|
|
276
278
|
yield `${syntax} `;
|
|
@@ -403,35 +405,6 @@ function* generateModelEmits(options, scriptSetup, scriptSetupRanges) {
|
|
|
403
405
|
}
|
|
404
406
|
}
|
|
405
407
|
}
|
|
406
|
-
function* generateStyleModules(options, ctx) {
|
|
407
|
-
const styles = options.sfc.styles.filter(style => style.module);
|
|
408
|
-
if (!styles.length) {
|
|
409
|
-
return;
|
|
410
|
-
}
|
|
411
|
-
yield `type __VLS_StyleModules = {${common_1.newLine}`;
|
|
412
|
-
for (let i = 0; i < styles.length; i++) {
|
|
413
|
-
const style = styles[i];
|
|
414
|
-
const { name, offset } = style.module;
|
|
415
|
-
if (offset) {
|
|
416
|
-
yield [
|
|
417
|
-
name,
|
|
418
|
-
'main',
|
|
419
|
-
offset + 1,
|
|
420
|
-
index_1.codeFeatures.all
|
|
421
|
-
];
|
|
422
|
-
}
|
|
423
|
-
else {
|
|
424
|
-
yield name;
|
|
425
|
-
}
|
|
426
|
-
yield `: Record<string, string> & ${ctx.localTypes.PrettifyLocal}<{}`;
|
|
427
|
-
for (const className of style.classNames) {
|
|
428
|
-
yield* (0, template_1.generateCssClassProperty)(i, className.text, className.offset, 'string', false);
|
|
429
|
-
}
|
|
430
|
-
yield `>${common_1.endOfLine}`;
|
|
431
|
-
}
|
|
432
|
-
yield `}`;
|
|
433
|
-
yield common_1.endOfLine;
|
|
434
|
-
}
|
|
435
408
|
function* generateDefinePropType(scriptSetup, propName, localName, defineProp) {
|
|
436
409
|
if (defineProp.type) {
|
|
437
410
|
// Infer from defineProp<T>
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Code } from '../../types';
|
|
2
|
+
import type { ScriptCodegenContext } from './context';
|
|
3
|
+
import { ScriptCodegenOptions } from './index';
|
|
4
|
+
export declare function generateStyleModulesType(options: ScriptCodegenOptions, ctx: ScriptCodegenContext): Generator<Code>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateStyleModulesType = generateStyleModulesType;
|
|
4
|
+
const index_1 = require("./index");
|
|
5
|
+
const template_1 = require("./template");
|
|
6
|
+
const common_1 = require("../common");
|
|
7
|
+
function* generateStyleModulesType(options, ctx) {
|
|
8
|
+
const styles = options.sfc.styles.filter(style => style.module);
|
|
9
|
+
if (!styles.length) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
yield `type __VLS_StyleModules = {${common_1.newLine}`;
|
|
13
|
+
for (let i = 0; i < styles.length; i++) {
|
|
14
|
+
const style = styles[i];
|
|
15
|
+
const { name, offset } = style.module;
|
|
16
|
+
if (offset) {
|
|
17
|
+
yield [
|
|
18
|
+
name,
|
|
19
|
+
'main',
|
|
20
|
+
offset + 1,
|
|
21
|
+
index_1.codeFeatures.all
|
|
22
|
+
];
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
yield name;
|
|
26
|
+
}
|
|
27
|
+
yield `: Record<string, string> & ${ctx.localTypes.PrettifyLocal}<{}`;
|
|
28
|
+
for (const className of style.classNames) {
|
|
29
|
+
yield* (0, template_1.generateCssClassProperty)(i, className.text, className.offset, 'string', false);
|
|
30
|
+
}
|
|
31
|
+
yield `>${common_1.endOfLine}`;
|
|
32
|
+
}
|
|
33
|
+
yield `}`;
|
|
34
|
+
yield common_1.endOfLine;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=styleModulesType.js.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Code } from '../../types';
|
|
2
|
+
import { TemplateCodegenContext } from '../template/context';
|
|
2
3
|
import type { ScriptCodegenContext } from './context';
|
|
3
4
|
import { type ScriptCodegenOptions } from './index';
|
|
4
|
-
export declare function
|
|
5
|
-
export declare function
|
|
6
|
-
export declare function generateTemplate(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, isClassComponent: boolean): Generator<Code>;
|
|
5
|
+
export declare function generateTemplateDirectives(options: ScriptCodegenOptions): Generator<Code>;
|
|
6
|
+
export declare function generateTemplate(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, isClassComponent: boolean): Generator<Code, TemplateCodegenContext>;
|
|
7
7
|
export declare function generateCssClassProperty(styleIndex: number, classNameWithDot: string, offset: number, propertyType: string, optional: boolean): Generator<Code>;
|
|
8
8
|
export declare function getTemplateUsageVars(options: ScriptCodegenOptions, ctx: ScriptCodegenContext): Set<string>;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.generateTemplateComponents = generateTemplateComponents;
|
|
3
|
+
exports.generateTemplateDirectives = generateTemplateDirectives;
|
|
5
4
|
exports.generateTemplate = generateTemplate;
|
|
6
5
|
exports.generateCssClassProperty = generateCssClassProperty;
|
|
7
6
|
exports.getTemplateUsageVars = getTemplateUsageVars;
|
|
@@ -11,54 +10,28 @@ const context_1 = require("../template/context");
|
|
|
11
10
|
const interpolation_1 = require("../template/interpolation");
|
|
12
11
|
const styleScopedClasses_1 = require("../template/styleScopedClasses");
|
|
13
12
|
const index_1 = require("./index");
|
|
14
|
-
const internalComponent_1 = require("./internalComponent");
|
|
15
13
|
function* generateTemplateCtx(options, isClassComponent) {
|
|
16
|
-
const
|
|
17
|
-
const extraExps = [];
|
|
14
|
+
const exps = [];
|
|
18
15
|
if (isClassComponent) {
|
|
19
|
-
|
|
16
|
+
exps.push(`this`);
|
|
20
17
|
}
|
|
21
18
|
else {
|
|
22
|
-
|
|
19
|
+
exps.push(`{} as InstanceType<__VLS_PickNotAny<typeof __VLS_self, new () => {}>>`);
|
|
23
20
|
}
|
|
24
21
|
if (options.vueCompilerOptions.petiteVueExtensions.some(ext => options.fileBaseName.endsWith(ext))) {
|
|
25
|
-
|
|
22
|
+
exps.push(`globalThis`);
|
|
26
23
|
}
|
|
27
24
|
if (options.sfc.styles.some(style => style.module)) {
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
if (options.scriptSetupRanges?.templateRefs.length) {
|
|
31
|
-
let exp = `{} as import('${options.vueCompilerOptions.lib}').UnwrapRef<{${common_1.newLine}`;
|
|
32
|
-
for (const { name } of options.scriptSetupRanges.templateRefs) {
|
|
33
|
-
if (name) {
|
|
34
|
-
exp += `${name}: typeof ${name}${common_1.newLine}`;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
exp += `}>${common_1.newLine}`;
|
|
38
|
-
extraExps.push(exp);
|
|
39
|
-
}
|
|
40
|
-
yield `const __VLS_ctxBase = `;
|
|
41
|
-
if (baseExps.length === 1) {
|
|
42
|
-
yield baseExps[0];
|
|
43
|
-
yield common_1.endOfLine;
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
yield `{${common_1.newLine}`;
|
|
47
|
-
for (const exp of baseExps) {
|
|
48
|
-
yield `...`;
|
|
49
|
-
yield exp;
|
|
50
|
-
yield `,${common_1.newLine}`;
|
|
51
|
-
}
|
|
52
|
-
yield `}${common_1.endOfLine}`;
|
|
25
|
+
exps.push(`{} as __VLS_StyleModules`);
|
|
53
26
|
}
|
|
54
27
|
yield `const __VLS_ctx = `;
|
|
55
|
-
if (
|
|
56
|
-
yield
|
|
28
|
+
if (exps.length === 1) {
|
|
29
|
+
yield exps[0];
|
|
30
|
+
yield `${common_1.endOfLine}`;
|
|
57
31
|
}
|
|
58
32
|
else {
|
|
59
33
|
yield `{${common_1.newLine}`;
|
|
60
|
-
|
|
61
|
-
for (const exp of extraExps) {
|
|
34
|
+
for (const exp of exps) {
|
|
62
35
|
yield `...`;
|
|
63
36
|
yield exp;
|
|
64
37
|
yield `,${common_1.newLine}`;
|
|
@@ -83,19 +56,18 @@ function* generateTemplateComponents(options) {
|
|
|
83
56
|
nameType = options.sfc.script.content.substring(nameOption.start, nameOption.end);
|
|
84
57
|
}
|
|
85
58
|
else if (options.sfc.scriptSetup) {
|
|
86
|
-
|
|
87
|
-
nameType = 'typeof __VLS_name';
|
|
59
|
+
nameType = `'${options.scriptSetupRanges?.options.name ?? options.fileBaseName.substring(0, options.fileBaseName.lastIndexOf('.'))}'`;
|
|
88
60
|
}
|
|
89
61
|
if (nameType) {
|
|
90
62
|
exps.push(`{} as {
|
|
91
|
-
[K in ${nameType}]: typeof
|
|
63
|
+
[K in ${nameType}]: typeof __VLS_self
|
|
92
64
|
& (new () => {
|
|
93
65
|
${(0, shared_1.getSlotsPropertyName)(options.vueCompilerOptions.target)}: typeof ${options.scriptSetupRanges?.slots?.name ?? '__VLS_slots'}
|
|
94
66
|
})
|
|
95
67
|
}`);
|
|
96
68
|
}
|
|
97
|
-
exps.push(`{} as NonNullable<typeof
|
|
98
|
-
exps.push(`
|
|
69
|
+
exps.push(`{} as NonNullable<typeof __VLS_self extends { components: infer C } ? C : {}>`);
|
|
70
|
+
exps.push(`__VLS_ctx`);
|
|
99
71
|
yield `const __VLS_localComponents = {${common_1.newLine}`;
|
|
100
72
|
for (const type of exps) {
|
|
101
73
|
yield `...`;
|
|
@@ -103,26 +75,41 @@ function* generateTemplateComponents(options) {
|
|
|
103
75
|
yield `,${common_1.newLine}`;
|
|
104
76
|
}
|
|
105
77
|
yield `}${common_1.endOfLine}`;
|
|
106
|
-
yield `let __VLS_components
|
|
78
|
+
yield `let __VLS_components!: typeof __VLS_localComponents & __VLS_GlobalComponents${common_1.endOfLine}`;
|
|
107
79
|
}
|
|
108
|
-
function*
|
|
109
|
-
|
|
110
|
-
if (
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
yield* (0, internalComponent_1.generateInternalComponent)(options, ctx, templateCodegenCtx);
|
|
80
|
+
function* generateTemplateDirectives(options) {
|
|
81
|
+
const exps = [];
|
|
82
|
+
if (options.sfc.script && options.scriptRanges?.exportDefault?.directivesOption) {
|
|
83
|
+
const { directivesOption } = options.scriptRanges.exportDefault;
|
|
84
|
+
exps.push([
|
|
85
|
+
options.sfc.script.content.substring(directivesOption.start, directivesOption.end),
|
|
86
|
+
'script',
|
|
87
|
+
directivesOption.start,
|
|
88
|
+
index_1.codeFeatures.navigation,
|
|
89
|
+
]);
|
|
119
90
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
yield
|
|
91
|
+
exps.push(`{} as NonNullable<typeof __VLS_self extends { directives: infer D } ? D : {}>`);
|
|
92
|
+
exps.push(`__VLS_ctx`);
|
|
93
|
+
yield `const __VLS_localDirectives = {${common_1.newLine}`;
|
|
94
|
+
for (const type of exps) {
|
|
95
|
+
yield `...`;
|
|
96
|
+
yield type;
|
|
97
|
+
yield `,${common_1.newLine}`;
|
|
125
98
|
}
|
|
99
|
+
yield `}${common_1.endOfLine}`;
|
|
100
|
+
yield `let __VLS_directives!: typeof __VLS_localDirectives & __VLS_GlobalDirectives${common_1.endOfLine}`;
|
|
101
|
+
}
|
|
102
|
+
function* generateTemplate(options, ctx, isClassComponent) {
|
|
103
|
+
ctx.generatedTemplate = true;
|
|
104
|
+
const templateCodegenCtx = (0, context_1.createTemplateCodegenContext)({
|
|
105
|
+
scriptSetupBindingNames: new Set(),
|
|
106
|
+
edited: options.edited,
|
|
107
|
+
});
|
|
108
|
+
yield* generateTemplateCtx(options, isClassComponent);
|
|
109
|
+
yield* generateTemplateComponents(options);
|
|
110
|
+
yield* generateTemplateDirectives(options);
|
|
111
|
+
yield* generateTemplateBody(options, templateCodegenCtx);
|
|
112
|
+
return templateCodegenCtx;
|
|
126
113
|
}
|
|
127
114
|
function* generateTemplateBody(options, templateCodegenCtx) {
|
|
128
115
|
const firstClasses = new Set();
|
|
@@ -157,14 +144,16 @@ function* generateTemplateBody(options, templateCodegenCtx) {
|
|
|
157
144
|
yield `// no template${common_1.newLine}`;
|
|
158
145
|
if (!options.scriptSetupRanges?.slots.define) {
|
|
159
146
|
yield `const __VLS_slots = {}${common_1.endOfLine}`;
|
|
160
|
-
yield `const $refs = {}${common_1.endOfLine}`;
|
|
161
|
-
yield `const __VLS_inheritedAttrs = {}${common_1.endOfLine}`;
|
|
162
147
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
yield `
|
|
148
|
+
yield `const __VLS_inheritedAttrs = {}${common_1.endOfLine}`;
|
|
149
|
+
yield `const $refs = {}${common_1.endOfLine}`;
|
|
150
|
+
yield `const $el = {} as any${common_1.endOfLine}`;
|
|
151
|
+
}
|
|
152
|
+
yield `return {${common_1.newLine}`;
|
|
153
|
+
yield ` attrs: {} as Partial<typeof __VLS_inheritedAttrs>,${common_1.newLine}`;
|
|
154
|
+
yield ` slots: ${options.scriptSetupRanges?.slots.name ?? '__VLS_slots'},${common_1.newLine}`;
|
|
155
|
+
yield ` refs: $refs,${common_1.newLine}`;
|
|
156
|
+
yield ` rootEl: $el,${common_1.newLine}`;
|
|
168
157
|
yield `}${common_1.endOfLine}`;
|
|
169
158
|
}
|
|
170
159
|
function* generateCssClassProperty(styleIndex, classNameWithDot, offset, propertyType, optional) {
|
|
@@ -199,7 +188,7 @@ function* generateCssVars(options, ctx) {
|
|
|
199
188
|
yield `// CSS variable injection ${common_1.newLine}`;
|
|
200
189
|
for (const style of options.sfc.styles) {
|
|
201
190
|
for (const cssBind of style.cssVars) {
|
|
202
|
-
for (const [segment, offset, onlyError] of (0, interpolation_1.forEachInterpolationSegment)(options.ts, ctx, cssBind.text, cssBind.offset, options.ts.createSourceFile('/a.txt', cssBind.text, 99))) {
|
|
191
|
+
for (const [segment, offset, onlyError] of (0, interpolation_1.forEachInterpolationSegment)(options.ts, undefined, undefined, ctx, cssBind.text, cssBind.offset, options.ts.createSourceFile('/a.txt', cssBind.text, 99))) {
|
|
203
192
|
if (offset === undefined) {
|
|
204
193
|
yield segment;
|
|
205
194
|
}
|
|
@@ -41,6 +41,8 @@ export declare function createTemplateCodegenContext(options: Pick<TemplateCodeg
|
|
|
41
41
|
inlayHints: InlayHintInfo[];
|
|
42
42
|
hasSlot: boolean;
|
|
43
43
|
inheritedAttrVars: Set<unknown>;
|
|
44
|
+
templateRefs: Map<string, [varName: string, offset: number]>;
|
|
45
|
+
singleRootElType: string | undefined;
|
|
44
46
|
singleRootNode: CompilerDOM.ElementNode | undefined;
|
|
45
47
|
accessExternalVariable(name: string, offset?: number): void;
|
|
46
48
|
hasLocalVariable: (name: string) => boolean;
|
|
@@ -95,6 +95,7 @@ function createTemplateCodegenContext(options) {
|
|
|
95
95
|
const scopedClasses = [];
|
|
96
96
|
const emptyClassOffsets = [];
|
|
97
97
|
const inlayHints = [];
|
|
98
|
+
const templateRefs = new Map();
|
|
98
99
|
return {
|
|
99
100
|
slots,
|
|
100
101
|
dynamicSlots,
|
|
@@ -108,6 +109,8 @@ function createTemplateCodegenContext(options) {
|
|
|
108
109
|
inlayHints,
|
|
109
110
|
hasSlot: false,
|
|
110
111
|
inheritedAttrVars: new Set(),
|
|
112
|
+
templateRefs,
|
|
113
|
+
singleRootElType: undefined,
|
|
111
114
|
singleRootNode: undefined,
|
|
112
115
|
accessExternalVariable(name, offset) {
|
|
113
116
|
let arr = accessExternalVariables.get(name);
|
|
@@ -151,17 +151,23 @@ function* generateComponent(options, ctx, node, currentComponent) {
|
|
|
151
151
|
yield common_1.endOfLine;
|
|
152
152
|
}
|
|
153
153
|
const [refName, offset] = yield* generateVScope(options, ctx, node, props);
|
|
154
|
-
|
|
154
|
+
const isRootNode = node === ctx.singleRootNode;
|
|
155
|
+
if (refName || isRootNode) {
|
|
155
156
|
const varName = ctx.getInternalVariable();
|
|
156
|
-
options.templateRefNames.set(refName, [varName, offset]);
|
|
157
157
|
ctx.usedComponentCtxVars.add(var_defineComponentCtx);
|
|
158
|
-
yield `var ${varName} = {} as (Parameters<typeof ${var_defineComponentCtx}['expose']
|
|
158
|
+
yield `var ${varName} = {} as (Parameters<NonNullable<typeof ${var_defineComponentCtx}['expose']>>[0] | null)`;
|
|
159
159
|
if (node.codegenNode?.type === CompilerDOM.NodeTypes.VNODE_CALL
|
|
160
160
|
&& node.codegenNode.props?.type === CompilerDOM.NodeTypes.JS_OBJECT_EXPRESSION
|
|
161
161
|
&& node.codegenNode.props.properties.some(({ key }) => key.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && key.content === 'ref_for')) {
|
|
162
162
|
yield `[]`;
|
|
163
163
|
}
|
|
164
164
|
yield `${common_1.endOfLine}`;
|
|
165
|
+
if (refName) {
|
|
166
|
+
ctx.templateRefs.set(refName, [varName, offset]);
|
|
167
|
+
}
|
|
168
|
+
if (isRootNode) {
|
|
169
|
+
ctx.singleRootElType = `NonNullable<typeof ${varName}>['$el']`;
|
|
170
|
+
}
|
|
165
171
|
}
|
|
166
172
|
const usedComponentEventsVar = yield* (0, elementEvents_1.generateElementEvents)(options, ctx, node, var_functionalComponent, var_componentInstance, var_componentEmit, var_componentEvents);
|
|
167
173
|
if (usedComponentEventsVar) {
|
|
@@ -184,7 +190,7 @@ function* generateComponent(options, ctx, node, currentComponent) {
|
|
|
184
190
|
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node, currentComponent, var_defineComponentCtx);
|
|
185
191
|
}
|
|
186
192
|
if (ctx.usedComponentCtxVars.has(var_defineComponentCtx)) {
|
|
187
|
-
yield `
|
|
193
|
+
yield `var ${var_defineComponentCtx}!: __VLS_PickFunctionalComponentCtx<typeof ${var_originalComponent}, typeof ${var_componentInstance}>${common_1.endOfLine}`;
|
|
188
194
|
}
|
|
189
195
|
}
|
|
190
196
|
function* generateElement(options, ctx, node, currentComponent, componentCtxVar) {
|
|
@@ -208,7 +214,10 @@ function* generateElement(options, ctx, node, currentComponent, componentCtxVar)
|
|
|
208
214
|
}
|
|
209
215
|
const [refName, offset] = yield* generateVScope(options, ctx, node, node.props);
|
|
210
216
|
if (refName) {
|
|
211
|
-
|
|
217
|
+
ctx.templateRefs.set(refName, [`__VLS_nativeElements['${node.tag}']`, offset]);
|
|
218
|
+
}
|
|
219
|
+
if (ctx.singleRootNode === node) {
|
|
220
|
+
ctx.singleRootElType = `typeof __VLS_nativeElements['${node.tag}']`;
|
|
212
221
|
}
|
|
213
222
|
const slotDir = node.props.find(p => p.type === CompilerDOM.NodeTypes.DIRECTIVE && p.name === 'slot');
|
|
214
223
|
if (slotDir && componentCtxVar) {
|
|
@@ -360,7 +369,7 @@ function* generateReferencesForElements(options, ctx, node) {
|
|
|
360
369
|
&& prop.name === 'ref'
|
|
361
370
|
&& prop.value) {
|
|
362
371
|
const [content, startOffset] = normalizeAttributeValue(prop.value);
|
|
363
|
-
yield `// @ts-ignore${common_1.newLine}`;
|
|
372
|
+
yield `// @ts-ignore navigation for \`const ${content} = ref()\`${common_1.newLine}`;
|
|
364
373
|
yield `__VLS_ctx`;
|
|
365
374
|
yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, content, startOffset, ctx.codeFeatures.navigation, prop.value.loc);
|
|
366
375
|
yield common_1.endOfLine;
|
|
@@ -21,7 +21,7 @@ function* generateElementDirectives(options, ctx, node) {
|
|
|
21
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
22
|
yield common_1.endOfLine;
|
|
23
23
|
}
|
|
24
|
-
yield* (0, common_1.wrapWith)(prop.loc.start.offset, prop.loc.end.offset, ctx.codeFeatures.verification, `__VLS_directiveAsFunction(
|
|
24
|
+
yield* (0, common_1.wrapWith)(prop.loc.start.offset, prop.loc.end.offset, ctx.codeFeatures.verification, `__VLS_directiveAsFunction(__VLS_directives.`, ...(0, camelized_1.generateCamelized)('v-' + prop.name, prop.loc.start.offset, {
|
|
25
25
|
...ctx.codeFeatures.all,
|
|
26
26
|
verification: false,
|
|
27
27
|
completion: {
|
|
@@ -136,7 +136,10 @@ function* generateEventExpression(options, ctx, prop) {
|
|
|
136
136
|
}
|
|
137
137
|
function isCompoundExpression(ts, ast) {
|
|
138
138
|
let result = true;
|
|
139
|
-
if (ast.statements.length ===
|
|
139
|
+
if (ast.statements.length === 0) {
|
|
140
|
+
result = false;
|
|
141
|
+
}
|
|
142
|
+
else if (ast.statements.length === 1) {
|
|
140
143
|
ts.forEachChild(ast, child_1 => {
|
|
141
144
|
if (ts.isExpressionStatement(child_1)) {
|
|
142
145
|
ts.forEachChild(child_1, child_2 => {
|
|
@@ -65,7 +65,7 @@ function* generateElementProps(options, ctx, node, props, enableCodeFeatures, pr
|
|
|
65
65
|
}
|
|
66
66
|
continue;
|
|
67
67
|
}
|
|
68
|
-
if (prop.modifiers.some(m => m === 'prop' || m === 'attr')) {
|
|
68
|
+
if (prop.modifiers.some(m => m.content === 'prop' || m.content === 'attr')) {
|
|
69
69
|
propName = propName.substring(1);
|
|
70
70
|
}
|
|
71
71
|
const shouldSpread = propName === 'style' || propName === 'class';
|
|
@@ -99,7 +99,7 @@ function* generateElementProps(options, ctx, node, props, enableCodeFeatures, pr
|
|
|
99
99
|
}
|
|
100
100
|
: false,
|
|
101
101
|
}, prop.loc.name_2 ?? (prop.loc.name_2 = {}), shouldCamelize)
|
|
102
|
-
: (0, common_1.wrapWith)(prop.loc.start.offset, prop.loc.start.offset + 'v-model'.length, ctx.codeFeatures.verification, propName)), `: (`, ...
|
|
102
|
+
: (0, common_1.wrapWith)(prop.loc.start.offset, prop.loc.start.offset + 'v-model'.length, ctx.codeFeatures.verification, propName)), `: (`, ...generatePropExp(options, ctx, prop, prop.exp, ctx.codeFeatures.all, prop.arg?.loc.start.offset === prop.exp?.loc.start.offset, enableCodeFeatures), `)`);
|
|
103
103
|
if (!enableCodeFeatures) {
|
|
104
104
|
yield (0, muggle_string_1.toString)([...codes]);
|
|
105
105
|
}
|
|
@@ -126,22 +126,9 @@ function* generateElementProps(options, ctx, node, props, enableCodeFeatures, pr
|
|
|
126
126
|
if (shouldSpread) {
|
|
127
127
|
yield `...{ `;
|
|
128
128
|
}
|
|
129
|
-
const codeInfo =
|
|
130
|
-
const codes = (0, common_1.conditionWrapWith)(enableCodeFeatures, prop.loc.start.offset, prop.loc.end.offset, ctx.codeFeatures.verification, ...(0, objectProperty_1.generateObjectProperty)(options, ctx, prop.name, prop.loc.start.offset, shouldCamelize
|
|
129
|
+
const codeInfo = shouldCamelize
|
|
131
130
|
? {
|
|
132
|
-
...
|
|
133
|
-
verification: options.vueCompilerOptions.strictTemplates
|
|
134
|
-
? codeInfo.verification
|
|
135
|
-
: {
|
|
136
|
-
shouldReport(_source, code) {
|
|
137
|
-
if (String(code) === '2353' || String(code) === '2561') {
|
|
138
|
-
return false;
|
|
139
|
-
}
|
|
140
|
-
return typeof codeInfo.verification === 'object'
|
|
141
|
-
? codeInfo.verification.shouldReport?.(_source, code) ?? true
|
|
142
|
-
: true;
|
|
143
|
-
},
|
|
144
|
-
},
|
|
131
|
+
...ctx.codeFeatures.withoutHighlightAndCompletion,
|
|
145
132
|
navigation: ctx.codeFeatures.withoutHighlightAndCompletion.navigation
|
|
146
133
|
? {
|
|
147
134
|
resolveRenameNewName: shared_1.camelize,
|
|
@@ -149,7 +136,23 @@ function* generateElementProps(options, ctx, node, props, enableCodeFeatures, pr
|
|
|
149
136
|
}
|
|
150
137
|
: false,
|
|
151
138
|
}
|
|
152
|
-
:
|
|
139
|
+
: {
|
|
140
|
+
...ctx.codeFeatures.withoutHighlightAndCompletion,
|
|
141
|
+
};
|
|
142
|
+
if (!options.vueCompilerOptions.strictTemplates) {
|
|
143
|
+
const verification = codeInfo.verification;
|
|
144
|
+
codeInfo.verification = {
|
|
145
|
+
shouldReport(_source, code) {
|
|
146
|
+
if (String(code) === '2353' || String(code) === '2561') {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
return typeof verification === 'object'
|
|
150
|
+
? verification.shouldReport?.(_source, code) ?? true
|
|
151
|
+
: true;
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
const codes = (0, common_1.conditionWrapWith)(enableCodeFeatures, prop.loc.start.offset, prop.loc.end.offset, ctx.codeFeatures.verification, ...(0, objectProperty_1.generateObjectProperty)(options, ctx, prop.name, prop.loc.start.offset, codeInfo, prop.loc.name_1 ?? (prop.loc.name_1 = {}), shouldCamelize), `: (`, ...(prop.value
|
|
153
156
|
? generateAttrValue(prop.value, ctx.codeFeatures.all)
|
|
154
157
|
: [`true`]), `)`);
|
|
155
158
|
if (!enableCodeFeatures) {
|
|
@@ -182,7 +185,13 @@ function* generateElementProps(options, ctx, node, props, enableCodeFeatures, pr
|
|
|
182
185
|
}
|
|
183
186
|
}
|
|
184
187
|
}
|
|
185
|
-
function*
|
|
188
|
+
function* generatePropExp(options, ctx, prop, exp, features, isShorthand, enableCodeFeatures) {
|
|
189
|
+
if (isShorthand && features.completion) {
|
|
190
|
+
features = {
|
|
191
|
+
...features,
|
|
192
|
+
completion: undefined,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
186
195
|
if (exp && exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY) { // style='z-index: 2' will compile to {'z-index':'2'}
|
|
187
196
|
if (!isShorthand) { // vue 3.4+
|
|
188
197
|
yield* (0, interpolation_1.generateInterpolation)(options, ctx, exp.loc.source, exp.loc, exp.loc.start.offset, features, '(', ')');
|
|
@@ -7,10 +7,11 @@ export interface TemplateCodegenOptions {
|
|
|
7
7
|
compilerOptions: ts.CompilerOptions;
|
|
8
8
|
vueCompilerOptions: VueCompilerOptions;
|
|
9
9
|
template: NonNullable<Sfc['template']>;
|
|
10
|
+
edited: boolean;
|
|
10
11
|
scriptSetupBindingNames: Set<string>;
|
|
11
12
|
scriptSetupImportComponentNames: Set<string>;
|
|
12
|
-
|
|
13
|
-
templateRefNames:
|
|
13
|
+
destructuredPropNames: Set<string>;
|
|
14
|
+
templateRefNames: Set<string>;
|
|
14
15
|
hasDefineSlots?: boolean;
|
|
15
16
|
slotsAssignName?: string;
|
|
16
17
|
propsAssignName?: string;
|