@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
|
@@ -18,79 +18,89 @@ function* generateTemplate(options) {
|
|
|
18
18
|
if (options.propsAssignName) {
|
|
19
19
|
ctx.addLocalVariable(options.propsAssignName);
|
|
20
20
|
}
|
|
21
|
+
ctx.addLocalVariable('$el');
|
|
21
22
|
ctx.addLocalVariable('$refs');
|
|
22
|
-
yield* generatePreResolveComponents();
|
|
23
|
+
yield* generatePreResolveComponents(options);
|
|
23
24
|
if (options.template.ast) {
|
|
24
25
|
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, options.template.ast, undefined, undefined, undefined);
|
|
25
26
|
}
|
|
26
27
|
yield* (0, styleScopedClasses_1.generateStyleScopedClasses)(ctx);
|
|
27
28
|
if (!options.hasDefineSlots) {
|
|
28
29
|
yield `var __VLS_slots!:`;
|
|
29
|
-
yield* generateSlotsType();
|
|
30
|
+
yield* generateSlotsType(options, ctx);
|
|
30
31
|
yield common_1.endOfLine;
|
|
31
32
|
}
|
|
32
|
-
yield* generateInheritedAttrs();
|
|
33
33
|
yield* ctx.generateAutoImportCompletion();
|
|
34
|
-
yield*
|
|
34
|
+
yield* generateInheritedAttrs(ctx);
|
|
35
|
+
yield* generateRefs(ctx);
|
|
36
|
+
yield* generateRootEl(ctx);
|
|
35
37
|
return ctx;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
yield `}${common_1.endOfLine}`;
|
|
43
|
-
yield `declare var $refs: typeof __VLS_refs${common_1.endOfLine}`;
|
|
38
|
+
}
|
|
39
|
+
function* generateSlotsType(options, ctx) {
|
|
40
|
+
for (const { expVar, varName } of ctx.dynamicSlots) {
|
|
41
|
+
ctx.hasSlot = true;
|
|
42
|
+
yield `Partial<Record<NonNullable<typeof ${expVar}>, (_: typeof ${varName}) => any>> &${common_1.newLine}`;
|
|
44
43
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
yield `{${common_1.newLine}`;
|
|
45
|
+
for (const slot of ctx.slots) {
|
|
46
|
+
ctx.hasSlot = true;
|
|
47
|
+
if (slot.name && slot.loc !== undefined) {
|
|
48
|
+
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slot.name, slot.loc, ctx.codeFeatures.withoutHighlightAndCompletion, slot.nodeLoc);
|
|
49
49
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
ctx.hasSlot = true;
|
|
53
|
-
if (slot.name && slot.loc !== undefined) {
|
|
54
|
-
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slot.name, slot.loc, ctx.codeFeatures.withoutHighlightAndCompletion, slot.nodeLoc);
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
yield* (0, common_1.wrapWith)(slot.tagRange[0], slot.tagRange[1], ctx.codeFeatures.withoutHighlightAndCompletion, `default`);
|
|
58
|
-
}
|
|
59
|
-
yield `?(_: typeof ${slot.varName}): any,${common_1.newLine}`;
|
|
50
|
+
else {
|
|
51
|
+
yield* (0, common_1.wrapWith)(slot.tagRange[0], slot.tagRange[1], ctx.codeFeatures.withoutHighlightAndCompletion, `default`);
|
|
60
52
|
}
|
|
61
|
-
yield
|
|
53
|
+
yield `?(_: typeof ${slot.varName}): any,${common_1.newLine}`;
|
|
62
54
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
yield
|
|
55
|
+
yield `}`;
|
|
56
|
+
}
|
|
57
|
+
function* generateInheritedAttrs(ctx) {
|
|
58
|
+
yield 'var __VLS_inheritedAttrs!: {}';
|
|
59
|
+
for (const varName of ctx.inheritedAttrVars) {
|
|
60
|
+
yield ` & typeof ${varName}`;
|
|
69
61
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
62
|
+
yield common_1.endOfLine;
|
|
63
|
+
}
|
|
64
|
+
function* generateRefs(ctx) {
|
|
65
|
+
yield `const __VLS_refs = {${common_1.newLine}`;
|
|
66
|
+
for (const [name, [varName, offset]] of ctx.templateRefs) {
|
|
67
|
+
yield* (0, stringLiteralKey_1.generateStringLiteralKey)(name, offset, ctx.codeFeatures.navigationAndCompletion);
|
|
68
|
+
yield `: ${varName},${common_1.newLine}`;
|
|
69
|
+
}
|
|
70
|
+
yield `}${common_1.endOfLine}`;
|
|
71
|
+
yield `var $refs!: typeof __VLS_refs${common_1.endOfLine}`;
|
|
72
|
+
}
|
|
73
|
+
function* generateRootEl(ctx) {
|
|
74
|
+
if (ctx.singleRootElType) {
|
|
75
|
+
yield `var $el!: ${ctx.singleRootElType}${common_1.endOfLine}`;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
yield `var $el!: any${common_1.endOfLine}`;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function* generatePreResolveComponents(options) {
|
|
82
|
+
yield `let __VLS_resolvedLocalAndGlobalComponents!: Required<{}`;
|
|
83
|
+
if (options.template.ast) {
|
|
84
|
+
const components = new Set();
|
|
85
|
+
for (const node of forEachElementNode(options.template.ast)) {
|
|
86
|
+
if (node.tagType === CompilerDOM.ElementTypes.COMPONENT
|
|
87
|
+
&& node.tag.toLowerCase() !== 'component'
|
|
88
|
+
&& !node.tag.includes('.') // namespace tag
|
|
89
|
+
) {
|
|
90
|
+
if (components.has(node.tag)) {
|
|
91
|
+
continue;
|
|
89
92
|
}
|
|
93
|
+
components.add(node.tag);
|
|
94
|
+
yield common_1.newLine;
|
|
95
|
+
yield ` & __VLS_WithComponent<'${(0, element_1.getCanonicalComponentName)(node.tag)}', typeof __VLS_localComponents, `;
|
|
96
|
+
yield (0, element_1.getPossibleOriginalComponentNames)(node.tag, false)
|
|
97
|
+
.map(name => `"${name}"`)
|
|
98
|
+
.join(', ');
|
|
99
|
+
yield `>`;
|
|
90
100
|
}
|
|
91
101
|
}
|
|
92
|
-
yield `>${common_1.endOfLine}`;
|
|
93
102
|
}
|
|
103
|
+
yield `>${common_1.endOfLine}`;
|
|
94
104
|
}
|
|
95
105
|
function* forEachElementNode(node) {
|
|
96
106
|
if (node.type === CompilerDOM.NodeTypes.ROOT) {
|
|
@@ -3,4 +3,4 @@ import type { Code, VueCodeInformation } from '../../types';
|
|
|
3
3
|
import type { TemplateCodegenContext } from './context';
|
|
4
4
|
import type { TemplateCodegenOptions } from './index';
|
|
5
5
|
export declare function generateInterpolation(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, _code: string, astHolder: any, start: number | undefined, data: VueCodeInformation | ((offset: number) => VueCodeInformation) | undefined, prefix: string, suffix: string): Generator<Code>;
|
|
6
|
-
export declare function forEachInterpolationSegment(ts: typeof import('typescript'), ctx: TemplateCodegenContext, code: string, offset: number | undefined, ast: ts.SourceFile): Generator<[fragment: string, offset: number | undefined,
|
|
6
|
+
export declare function forEachInterpolationSegment(ts: typeof import('typescript'), destructuredPropNames: Set<string> | undefined, templateRefNames: Set<string> | undefined, ctx: TemplateCodegenContext, code: string, offset: number | undefined, ast: ts.SourceFile): Generator<[fragment: string, offset: number | undefined, type?: 'errorMappingOnly' | 'startText' | 'endText']>;
|
|
@@ -9,7 +9,7 @@ function* generateInterpolation(options, ctx, _code, astHolder, start, data, pre
|
|
|
9
9
|
const code = prefix + _code + suffix;
|
|
10
10
|
const ast = (0, common_1.createTsAst)(options.ts, astHolder, code);
|
|
11
11
|
const vars = [];
|
|
12
|
-
for (let [section, offset,
|
|
12
|
+
for (let [section, offset, type] of forEachInterpolationSegment(options.ts, options.destructuredPropNames, options.templateRefNames, ctx, code, start !== undefined ? start - prefix.length : undefined, ast)) {
|
|
13
13
|
if (offset === undefined) {
|
|
14
14
|
yield section;
|
|
15
15
|
}
|
|
@@ -26,18 +26,22 @@ function* generateInterpolation(options, ctx, _code, astHolder, start, data, pre
|
|
|
26
26
|
section = section.substring(-offset);
|
|
27
27
|
offset = 0;
|
|
28
28
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
29
|
+
const shouldSkip = section.length === 0 && (type === 'startText' || type === 'endText');
|
|
30
|
+
if (!shouldSkip) {
|
|
31
|
+
if (start !== undefined
|
|
32
|
+
&& data) {
|
|
33
|
+
yield [
|
|
34
|
+
section,
|
|
35
|
+
'template',
|
|
36
|
+
start + offset,
|
|
37
|
+
type === 'errorMappingOnly'
|
|
38
|
+
? ctx.codeFeatures.verification
|
|
39
|
+
: typeof data === 'function' ? data(start + offset) : data,
|
|
40
|
+
];
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
yield section;
|
|
44
|
+
}
|
|
41
45
|
}
|
|
42
46
|
yield addSuffix;
|
|
43
47
|
}
|
|
@@ -48,7 +52,7 @@ function* generateInterpolation(options, ctx, _code, astHolder, start, data, pre
|
|
|
48
52
|
}
|
|
49
53
|
}
|
|
50
54
|
}
|
|
51
|
-
function* forEachInterpolationSegment(ts, ctx, code, offset, ast) {
|
|
55
|
+
function* forEachInterpolationSegment(ts, destructuredPropNames, templateRefNames, ctx, code, offset, ast) {
|
|
52
56
|
let ctxVars = [];
|
|
53
57
|
const varCb = (id, isShorthand) => {
|
|
54
58
|
const text = (0, scriptSetupRanges_1.getNodeText)(ts, id, ast);
|
|
@@ -65,6 +69,9 @@ function* forEachInterpolationSegment(ts, ctx, code, offset, ast) {
|
|
|
65
69
|
isShorthand: isShorthand,
|
|
66
70
|
offset: (0, scriptSetupRanges_1.getStartEnd)(ts, id, ast).start,
|
|
67
71
|
});
|
|
72
|
+
if (destructuredPropNames?.has(text)) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
68
75
|
if (offset !== undefined) {
|
|
69
76
|
ctx.accessExternalVariable(text, offset + (0, scriptSetupRanges_1.getStartEnd)(ts, id, ast).start);
|
|
70
77
|
}
|
|
@@ -80,30 +87,49 @@ function* forEachInterpolationSegment(ts, ctx, code, offset, ast) {
|
|
|
80
87
|
yield [code.substring(0, ctxVars[0].offset + ctxVars[0].text.length), 0];
|
|
81
88
|
yield [': ', undefined];
|
|
82
89
|
}
|
|
83
|
-
else {
|
|
84
|
-
yield [code.substring(0, ctxVars[0].offset), 0];
|
|
90
|
+
else if (ctxVars[0].offset > 0) {
|
|
91
|
+
yield [code.substring(0, ctxVars[0].offset), 0, 'startText'];
|
|
85
92
|
}
|
|
86
93
|
for (let i = 0; i < ctxVars.length - 1; i++) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
yield
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
yield [code.substring(ctxVars[i].offset, ctxVars[i + 1].offset + ctxVars[i + 1].text.length), ctxVars[i].offset];
|
|
94
|
+
const curVar = ctxVars[i];
|
|
95
|
+
const nextVar = ctxVars[i + 1];
|
|
96
|
+
yield* generateVar(code, destructuredPropNames, templateRefNames, curVar, nextVar);
|
|
97
|
+
if (nextVar.isShorthand) {
|
|
98
|
+
yield [code.substring(curVar.offset + curVar.text.length, nextVar.offset + nextVar.text.length), curVar.offset + curVar.text.length];
|
|
93
99
|
yield [': ', undefined];
|
|
94
100
|
}
|
|
95
101
|
else {
|
|
96
|
-
yield [code.substring(
|
|
102
|
+
yield [code.substring(curVar.offset + curVar.text.length, nextVar.offset), curVar.offset + curVar.text.length];
|
|
97
103
|
}
|
|
98
104
|
}
|
|
99
|
-
|
|
100
|
-
yield
|
|
101
|
-
|
|
105
|
+
const lastVar = ctxVars.at(-1);
|
|
106
|
+
yield* generateVar(code, destructuredPropNames, templateRefNames, lastVar);
|
|
107
|
+
if (lastVar.offset + lastVar.text.length < code.length) {
|
|
108
|
+
yield [code.substring(lastVar.offset + lastVar.text.length), lastVar.offset + lastVar.text.length, 'endText'];
|
|
109
|
+
}
|
|
102
110
|
}
|
|
103
111
|
else {
|
|
104
112
|
yield [code, 0];
|
|
105
113
|
}
|
|
106
114
|
}
|
|
115
|
+
function* generateVar(code, destructuredPropNames, templateRefNames, curVar, nextVar = curVar) {
|
|
116
|
+
// fix https://github.com/vuejs/language-tools/issues/1205
|
|
117
|
+
// fix https://github.com/vuejs/language-tools/issues/1264
|
|
118
|
+
yield ['', nextVar.offset, 'errorMappingOnly'];
|
|
119
|
+
const isDestructuredProp = destructuredPropNames?.has(curVar.text) ?? false;
|
|
120
|
+
const isTemplateRef = templateRefNames?.has(curVar.text) ?? false;
|
|
121
|
+
if (isTemplateRef) {
|
|
122
|
+
yield [`__VLS_unref(`, undefined];
|
|
123
|
+
yield [code.substring(curVar.offset, curVar.offset + curVar.text.length), curVar.offset];
|
|
124
|
+
yield [`)`, undefined];
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
if (!isDestructuredProp) {
|
|
128
|
+
yield [`__VLS_ctx.`, undefined];
|
|
129
|
+
}
|
|
130
|
+
yield [code.substring(curVar.offset, curVar.offset + curVar.text.length), curVar.offset];
|
|
131
|
+
}
|
|
132
|
+
}
|
|
107
133
|
function walkIdentifiers(ts, node, ast, cb, ctx, blockVars = [], isRoot = true) {
|
|
108
134
|
if (ts.isIdentifier(node)) {
|
|
109
135
|
cb(node, false);
|
|
@@ -40,6 +40,10 @@ function* generateTemplateChild(options, ctx, node, currentComponent, prevNode,
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
const shouldInheritRootNodeAttrs = options.inheritAttrs;
|
|
43
|
+
const cur = node;
|
|
44
|
+
if (cur.codegenNode?.type === CompilerDOM.NodeTypes.JS_CACHE_EXPRESSION) {
|
|
45
|
+
cur.codegenNode = cur.codegenNode.value;
|
|
46
|
+
}
|
|
43
47
|
if (node.type === CompilerDOM.NodeTypes.ROOT) {
|
|
44
48
|
let prev;
|
|
45
49
|
if (shouldInheritRootNodeAttrs && node.children.length === 1 && node.children[0].type === CompilerDOM.NodeTypes.ELEMENT) {
|
|
@@ -9,6 +9,7 @@ export declare function parseScriptRanges(ts: typeof import('typescript'), ast:
|
|
|
9
9
|
argsNode: ts.ObjectLiteralExpression | undefined;
|
|
10
10
|
componentsOption: TextRange | undefined;
|
|
11
11
|
componentsOptionNode: ts.ObjectLiteralExpression | undefined;
|
|
12
|
+
directivesOption: TextRange | undefined;
|
|
12
13
|
nameOption: TextRange | undefined;
|
|
13
14
|
inheritAttrsOption: string | undefined;
|
|
14
15
|
}) | undefined;
|
|
@@ -24,6 +24,7 @@ function parseScriptRanges(ts, ast, hasScriptSetup, withNode) {
|
|
|
24
24
|
}
|
|
25
25
|
if (obj) {
|
|
26
26
|
let componentsOptionNode;
|
|
27
|
+
let directivesOptionNode;
|
|
27
28
|
let nameOptionNode;
|
|
28
29
|
let inheritAttrsOption;
|
|
29
30
|
ts.forEachChild(obj, node => {
|
|
@@ -32,10 +33,13 @@ function parseScriptRanges(ts, ast, hasScriptSetup, withNode) {
|
|
|
32
33
|
if (name === 'components' && ts.isObjectLiteralExpression(node.initializer)) {
|
|
33
34
|
componentsOptionNode = node.initializer;
|
|
34
35
|
}
|
|
35
|
-
if (name === '
|
|
36
|
+
else if (name === 'directives' && ts.isObjectLiteralExpression(node.initializer)) {
|
|
37
|
+
directivesOptionNode = node.initializer;
|
|
38
|
+
}
|
|
39
|
+
else if (name === 'name') {
|
|
36
40
|
nameOptionNode = node.initializer;
|
|
37
41
|
}
|
|
38
|
-
if (name === 'inheritAttrs') {
|
|
42
|
+
else if (name === 'inheritAttrs') {
|
|
39
43
|
inheritAttrsOption = (0, scriptSetupRanges_1.getNodeText)(ts, node.initializer, ast);
|
|
40
44
|
}
|
|
41
45
|
}
|
|
@@ -47,6 +51,7 @@ function parseScriptRanges(ts, ast, hasScriptSetup, withNode) {
|
|
|
47
51
|
argsNode: withNode ? obj : undefined,
|
|
48
52
|
componentsOption: componentsOptionNode ? _getStartEnd(componentsOptionNode) : undefined,
|
|
49
53
|
componentsOptionNode: withNode ? componentsOptionNode : undefined,
|
|
54
|
+
directivesOption: directivesOptionNode ? _getStartEnd(directivesOptionNode) : undefined,
|
|
50
55
|
nameOption: nameOptionNode ? _getStartEnd(nameOptionNode) : undefined,
|
|
51
56
|
inheritAttrsOption,
|
|
52
57
|
};
|
|
@@ -9,7 +9,8 @@ export declare function parseScriptSetupRanges(ts: typeof import('typescript'),
|
|
|
9
9
|
importComponentNames: Set<string>;
|
|
10
10
|
props: {
|
|
11
11
|
name?: string;
|
|
12
|
-
destructured?: string
|
|
12
|
+
destructured?: Set<string>;
|
|
13
|
+
destructuredRest?: string;
|
|
13
14
|
define?: ReturnType<(node: ts.CallExpression) => TextRange & {
|
|
14
15
|
arg?: TextRange;
|
|
15
16
|
typeArg?: TextRange;
|
|
@@ -236,7 +236,17 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
236
236
|
else if (vueCompilerOptions.macros.defineProps.includes(callText)) {
|
|
237
237
|
if (ts.isVariableDeclaration(parent)) {
|
|
238
238
|
if (ts.isObjectBindingPattern(parent.name)) {
|
|
239
|
-
props.destructured =
|
|
239
|
+
props.destructured = new Set();
|
|
240
|
+
const identifiers = (0, common_1.collectIdentifiers)(ts, parent.name, []);
|
|
241
|
+
for (const [id, isRest] of identifiers) {
|
|
242
|
+
const name = getNodeText(ts, id, ast);
|
|
243
|
+
if (isRest) {
|
|
244
|
+
props.destructuredRest = name;
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
props.destructured.add(name);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
240
250
|
}
|
|
241
251
|
else {
|
|
242
252
|
props.name = getNodeText(ts, parent.name, ast);
|
|
@@ -296,7 +306,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
296
306
|
}
|
|
297
307
|
}
|
|
298
308
|
}
|
|
299
|
-
else if (vueCompilerOptions.
|
|
309
|
+
else if (vueCompilerOptions.composibles.useTemplateRef.includes(callText) && node.arguments.length && !node.typeArguments?.length) {
|
|
300
310
|
const define = parseDefineFunction(node);
|
|
301
311
|
define.arg = _getStartEnd(node.arguments[0]);
|
|
302
312
|
let name;
|
|
@@ -5,7 +5,7 @@ const plugin = () => {
|
|
|
5
5
|
return {
|
|
6
6
|
version: 2.1,
|
|
7
7
|
getEmbeddedCodes(_fileName, sfc) {
|
|
8
|
-
if (sfc.template) {
|
|
8
|
+
if (sfc.template?.lang === 'html') {
|
|
9
9
|
return [{
|
|
10
10
|
id: 'template',
|
|
11
11
|
lang: sfc.template.lang,
|
|
@@ -14,7 +14,7 @@ const plugin = () => {
|
|
|
14
14
|
return [];
|
|
15
15
|
},
|
|
16
16
|
resolveEmbeddedCode(_fileName, sfc, embeddedFile) {
|
|
17
|
-
if (embeddedFile.id === 'template' && sfc.template) {
|
|
17
|
+
if (embeddedFile.id === 'template' && sfc.template?.lang === 'html') {
|
|
18
18
|
embeddedFile.content.push([
|
|
19
19
|
sfc.template.content,
|
|
20
20
|
sfc.template.name,
|
package/lib/plugins/vue-tsx.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
8
8
|
argsNode: import("typescript").ObjectLiteralExpression | undefined;
|
|
9
9
|
componentsOption: import("../types").TextRange | undefined;
|
|
10
10
|
componentsOptionNode: import("typescript").ObjectLiteralExpression | undefined;
|
|
11
|
+
directivesOption: import("../types").TextRange | undefined;
|
|
11
12
|
nameOption: import("../types").TextRange | undefined;
|
|
12
13
|
inheritAttrsOption: string | undefined;
|
|
13
14
|
}) | undefined;
|
|
@@ -21,7 +22,8 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
21
22
|
importComponentNames: Set<string>;
|
|
22
23
|
props: {
|
|
23
24
|
name?: string;
|
|
24
|
-
destructured?: string
|
|
25
|
+
destructured?: Set<string>;
|
|
26
|
+
destructuredRest?: string;
|
|
25
27
|
define?: ReturnType<(node: import("typescript").CallExpression) => import("../types").TextRange & {
|
|
26
28
|
arg?: import("../types").TextRange;
|
|
27
29
|
typeArg?: import("../types").TextRange;
|
|
@@ -143,6 +145,8 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
143
145
|
inlayHints: import("../codegen/types").InlayHintInfo[];
|
|
144
146
|
hasSlot: boolean;
|
|
145
147
|
inheritedAttrVars: Set<unknown>;
|
|
148
|
+
templateRefs: Map<string, [varName: string, offset: number]>;
|
|
149
|
+
singleRootElType: string | undefined;
|
|
146
150
|
singleRootNode: import("@vue/compiler-dom").ElementNode | undefined;
|
|
147
151
|
accessExternalVariable(name: string, offset?: number): void;
|
|
148
152
|
hasLocalVariable: (name: string) => boolean;
|
package/lib/plugins/vue-tsx.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.tsCodegen = void 0;
|
|
4
4
|
const computeds_1 = require("computeds");
|
|
5
|
-
const
|
|
5
|
+
const path_browserify_1 = require("path-browserify");
|
|
6
6
|
const script_1 = require("../codegen/script");
|
|
7
7
|
const template_1 = require("../codegen/template");
|
|
8
8
|
const scriptRanges_1 = require("../parsers/scriptRanges");
|
|
@@ -10,6 +10,7 @@ const scriptSetupRanges_1 = require("../parsers/scriptSetupRanges");
|
|
|
10
10
|
exports.tsCodegen = new WeakMap();
|
|
11
11
|
const fileEditTimes = new Map();
|
|
12
12
|
const plugin = ctx => {
|
|
13
|
+
let appendedGlobalTypes = false;
|
|
13
14
|
return {
|
|
14
15
|
version: 2.1,
|
|
15
16
|
requiredCompilerOptions: [
|
|
@@ -38,13 +39,18 @@ const plugin = ctx => {
|
|
|
38
39
|
};
|
|
39
40
|
function useTsx(fileName, sfc) {
|
|
40
41
|
if (!exports.tsCodegen.has(sfc)) {
|
|
41
|
-
|
|
42
|
+
let appendGlobalTypes = false;
|
|
43
|
+
if (!ctx.vueCompilerOptions.__setupedGlobalTypes && !appendedGlobalTypes) {
|
|
44
|
+
appendGlobalTypes = true;
|
|
45
|
+
appendedGlobalTypes = true;
|
|
46
|
+
}
|
|
47
|
+
exports.tsCodegen.set(sfc, createTsx(fileName, sfc, ctx, appendGlobalTypes));
|
|
42
48
|
}
|
|
43
49
|
return exports.tsCodegen.get(sfc);
|
|
44
50
|
}
|
|
45
51
|
};
|
|
46
52
|
exports.default = plugin;
|
|
47
|
-
function createTsx(fileName, _sfc, ctx) {
|
|
53
|
+
function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
|
|
48
54
|
const ts = ctx.modules.typescript;
|
|
49
55
|
const lang = (0, computeds_1.computed)(() => {
|
|
50
56
|
return !_sfc.script && !_sfc.scriptSetup ? 'ts'
|
|
@@ -59,7 +65,7 @@ function createTsx(fileName, _sfc, ctx) {
|
|
|
59
65
|
? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, _sfc.scriptSetup.ast, ctx.vueCompilerOptions)
|
|
60
66
|
: undefined);
|
|
61
67
|
const generatedTemplate = (0, computeds_1.computed)(() => {
|
|
62
|
-
if (!_sfc.template) {
|
|
68
|
+
if (ctx.vueCompilerOptions.skipTemplateCodegen || !_sfc.template) {
|
|
63
69
|
return;
|
|
64
70
|
}
|
|
65
71
|
const codes = [];
|
|
@@ -71,7 +77,8 @@ function createTsx(fileName, _sfc, ctx) {
|
|
|
71
77
|
edited: ctx.vueCompilerOptions.__test || (fileEditTimes.get(fileName) ?? 0) >= 2,
|
|
72
78
|
scriptSetupBindingNames: scriptSetupBindingNames(),
|
|
73
79
|
scriptSetupImportComponentNames: scriptSetupImportComponentNames(),
|
|
74
|
-
|
|
80
|
+
destructuredPropNames: destructuredPropNames(),
|
|
81
|
+
templateRefNames: templateRefNames(),
|
|
75
82
|
hasDefineSlots: hasDefineSlots(),
|
|
76
83
|
slotsAssignName: slotsAssignName(),
|
|
77
84
|
propsAssignName: propsAssignName(),
|
|
@@ -88,7 +95,6 @@ function createTsx(fileName, _sfc, ctx) {
|
|
|
88
95
|
codes: codes,
|
|
89
96
|
};
|
|
90
97
|
});
|
|
91
|
-
const hasDefineSlots = (0, computeds_1.computed)(() => !!scriptSetupRanges()?.slots.define);
|
|
92
98
|
const scriptSetupBindingNames = (0, computeds_1.computed)(oldNames => {
|
|
93
99
|
const newNames = new Set();
|
|
94
100
|
const bindings = scriptSetupRanges()?.bindings;
|
|
@@ -104,11 +110,32 @@ function createTsx(fileName, _sfc, ctx) {
|
|
|
104
110
|
});
|
|
105
111
|
const scriptSetupImportComponentNames = (0, computeds_1.computed)(oldNames => {
|
|
106
112
|
const newNames = scriptSetupRanges()?.importComponentNames ?? new Set();
|
|
107
|
-
if (
|
|
113
|
+
if (oldNames && twoSetsEqual(newNames, oldNames)) {
|
|
108
114
|
return oldNames;
|
|
109
115
|
}
|
|
110
116
|
return newNames;
|
|
111
117
|
});
|
|
118
|
+
const destructuredPropNames = (0, computeds_1.computed)(oldNames => {
|
|
119
|
+
const newNames = scriptSetupRanges()?.props.destructured ?? new Set();
|
|
120
|
+
const rest = scriptSetupRanges()?.props.destructuredRest;
|
|
121
|
+
if (rest) {
|
|
122
|
+
newNames.add(rest);
|
|
123
|
+
}
|
|
124
|
+
if (oldNames && twoSetsEqual(newNames, oldNames)) {
|
|
125
|
+
return oldNames;
|
|
126
|
+
}
|
|
127
|
+
return newNames;
|
|
128
|
+
});
|
|
129
|
+
const templateRefNames = (0, computeds_1.computed)(oldNames => {
|
|
130
|
+
const newNames = new Set(scriptSetupRanges()?.templateRefs
|
|
131
|
+
.map(({ name }) => name)
|
|
132
|
+
.filter(name => name !== undefined));
|
|
133
|
+
if (oldNames && twoSetsEqual(newNames, oldNames)) {
|
|
134
|
+
return oldNames;
|
|
135
|
+
}
|
|
136
|
+
return newNames;
|
|
137
|
+
});
|
|
138
|
+
const hasDefineSlots = (0, computeds_1.computed)(() => !!scriptSetupRanges()?.slots.define);
|
|
112
139
|
const slotsAssignName = (0, computeds_1.computed)(() => scriptSetupRanges()?.slots.name);
|
|
113
140
|
const propsAssignName = (0, computeds_1.computed)(() => scriptSetupRanges()?.props.name);
|
|
114
141
|
const inheritAttrs = (0, computeds_1.computed)(() => {
|
|
@@ -118,21 +145,21 @@ function createTsx(fileName, _sfc, ctx) {
|
|
|
118
145
|
const generatedScript = (0, computeds_1.computed)(() => {
|
|
119
146
|
const codes = [];
|
|
120
147
|
const linkedCodeMappings = [];
|
|
121
|
-
const _template = generatedTemplate();
|
|
122
148
|
let generatedLength = 0;
|
|
123
149
|
const codegen = (0, script_1.generateScript)({
|
|
124
150
|
ts,
|
|
125
|
-
fileBaseName:
|
|
151
|
+
fileBaseName: path_browserify_1.posix.basename(fileName),
|
|
126
152
|
sfc: _sfc,
|
|
127
153
|
lang: lang(),
|
|
128
154
|
scriptRanges: scriptRanges(),
|
|
129
155
|
scriptSetupRanges: scriptSetupRanges(),
|
|
130
|
-
templateCodegen:
|
|
156
|
+
templateCodegen: generatedTemplate(),
|
|
131
157
|
compilerOptions: ctx.compilerOptions,
|
|
132
158
|
vueCompilerOptions: ctx.vueCompilerOptions,
|
|
133
159
|
edited: ctx.vueCompilerOptions.__test || (fileEditTimes.get(fileName) ?? 0) >= 2,
|
|
134
160
|
getGeneratedLength: () => generatedLength,
|
|
135
161
|
linkedCodeMappings,
|
|
162
|
+
appendGlobalTypes,
|
|
136
163
|
});
|
|
137
164
|
fileEditTimes.set(fileName, (fileEditTimes.get(fileName) ?? 0) + 1);
|
|
138
165
|
let current = codegen.next();
|
package/lib/types.d.ts
CHANGED
|
@@ -36,16 +36,16 @@ export interface VueCompilerOptions {
|
|
|
36
36
|
defineModel: string[];
|
|
37
37
|
defineOptions: string[];
|
|
38
38
|
withDefaults: string[];
|
|
39
|
-
templateRef: string[];
|
|
40
39
|
};
|
|
41
40
|
composibles: {
|
|
42
41
|
useCssModule: string[];
|
|
42
|
+
useTemplateRef: string[];
|
|
43
43
|
};
|
|
44
44
|
plugins: VueLanguagePlugin[];
|
|
45
45
|
experimentalDefinePropProposal: 'kevinEdition' | 'johnsonEdition' | false;
|
|
46
46
|
experimentalResolveStyleCssClasses: 'scoped' | 'always' | 'never';
|
|
47
47
|
experimentalModelPropName: Record<string, Record<string, boolean | Record<string, string> | Record<string, string>[]>>;
|
|
48
|
-
__setupedGlobalTypes?:
|
|
48
|
+
__setupedGlobalTypes?: boolean;
|
|
49
49
|
__test?: boolean;
|
|
50
50
|
}
|
|
51
51
|
export declare const validVersions: readonly [2, 2.1];
|
package/lib/utils/ts.d.ts
CHANGED
|
@@ -3,6 +3,12 @@ import type { VueCompilerOptions } from '../types';
|
|
|
3
3
|
export type ParsedCommandLine = ts.ParsedCommandLine & {
|
|
4
4
|
vueOptions: VueCompilerOptions;
|
|
5
5
|
};
|
|
6
|
-
export declare function createParsedCommandLineByJson(ts: typeof import('typescript'), parseConfigHost: ts.ParseConfigHost
|
|
7
|
-
|
|
6
|
+
export declare function createParsedCommandLineByJson(ts: typeof import('typescript'), parseConfigHost: ts.ParseConfigHost & {
|
|
7
|
+
writeFile?(path: string, data: string): void;
|
|
8
|
+
}, rootDir: string, json: any, configFileName?: string, skipGlobalTypesSetup?: boolean): ParsedCommandLine;
|
|
9
|
+
export declare function createParsedCommandLine(ts: typeof import('typescript'), parseConfigHost: ts.ParseConfigHost, tsConfigPath: string, skipGlobalTypesSetup?: boolean): ParsedCommandLine;
|
|
8
10
|
export declare function resolveVueCompilerOptions(vueOptions: Partial<VueCompilerOptions>): VueCompilerOptions;
|
|
11
|
+
export declare function setupGlobalTypes(rootDir: string, vueOptions: VueCompilerOptions, host: {
|
|
12
|
+
fileExists(path: string): boolean;
|
|
13
|
+
writeFile?(path: string, data: string): void;
|
|
14
|
+
}): boolean;
|