@vue/language-core 2.2.2 → 2.2.6
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/globalTypes.js +21 -34
- package/lib/codegen/script/component.js +11 -9
- package/lib/codegen/script/componentSelf.js +4 -11
- package/lib/codegen/script/context.d.ts +0 -1
- package/lib/codegen/script/context.js +0 -1
- package/lib/codegen/script/index.d.ts +1 -4
- package/lib/codegen/script/index.js +8 -12
- package/lib/codegen/script/scriptSetup.js +90 -70
- package/lib/codegen/script/src.d.ts +2 -2
- package/lib/codegen/script/src.js +36 -37
- package/lib/codegen/script/styleModulesType.d.ts +1 -1
- package/lib/codegen/script/styleModulesType.js +2 -2
- package/lib/codegen/script/template.d.ts +1 -2
- package/lib/codegen/script/template.js +5 -53
- package/lib/codegen/style/classProperty.d.ts +2 -0
- package/lib/codegen/style/classProperty.js +18 -0
- package/lib/codegen/style/modules.d.ts +3 -0
- package/lib/codegen/style/modules.js +34 -0
- package/lib/codegen/style/scopedClasses.d.ts +4 -0
- package/lib/codegen/style/scopedClasses.js +32 -0
- package/lib/codegen/template/context.d.ts +106 -5
- package/lib/codegen/template/context.js +131 -6
- package/lib/codegen/template/element.d.ts +1 -1
- package/lib/codegen/template/element.js +74 -97
- package/lib/codegen/template/elementChildren.d.ts +1 -1
- package/lib/codegen/template/elementChildren.js +1 -13
- package/lib/codegen/template/elementDirectives.js +8 -6
- package/lib/codegen/template/elementEvents.d.ts +2 -1
- package/lib/codegen/template/elementEvents.js +52 -28
- package/lib/codegen/template/elementProps.d.ts +1 -1
- package/lib/codegen/template/elementProps.js +23 -20
- package/lib/codegen/template/index.js +29 -14
- package/lib/codegen/template/interpolation.js +5 -5
- package/lib/codegen/template/objectProperty.js +5 -4
- package/lib/codegen/template/propertyAccess.js +1 -1
- package/lib/codegen/template/slotOutlet.js +13 -11
- package/lib/codegen/template/styleScopedClasses.js +8 -58
- package/lib/codegen/template/templateChild.js +60 -28
- package/lib/codegen/template/vFor.js +2 -2
- package/lib/codegen/template/vIf.js +4 -8
- package/lib/codegen/template/vSlot.d.ts +1 -0
- package/lib/codegen/template/vSlot.js +14 -1
- package/lib/codegen/utils/camelized.d.ts +1 -1
- package/lib/codegen/utils/camelized.js +6 -6
- package/lib/codegen/utils/escaped.d.ts +2 -0
- package/lib/codegen/utils/escaped.js +23 -0
- package/lib/codegen/utils/index.d.ts +3 -3
- package/lib/codegen/utils/index.js +19 -15
- package/lib/codegen/utils/objectProperty.d.ts +3 -0
- package/lib/codegen/utils/objectProperty.js +41 -0
- package/lib/codegen/utils/stringLiteralKey.js +2 -1
- package/lib/codegen/utils/unicode.js +2 -2
- package/lib/codegen/utils/wrapWith.d.ts +3 -0
- package/lib/codegen/utils/wrapWith.js +24 -0
- package/lib/parsers/scriptSetupRanges.d.ts +2 -0
- package/lib/parsers/scriptSetupRanges.js +84 -106
- package/lib/plugins/file-md.js +3 -0
- package/lib/plugins/vue-template-inline-ts.js +3 -3
- package/lib/plugins/vue-tsx.d.ts +11 -8
- package/lib/plugins/vue-tsx.js +19 -28
- package/lib/types.d.ts +24 -14
- package/lib/utils/parseSfc.js +40 -16
- package/lib/utils/ts.js +17 -0
- package/lib/virtualFile/computedEmbeddedCodes.js +18 -11
- package/lib/virtualFile/computedSfc.js +21 -28
- package/lib/virtualFile/vueFile.d.ts +7 -10
- package/lib/virtualFile/vueFile.js +10 -4
- package/package.json +2 -2
- package/lib/codeFeatures.d.ts +0 -1
- package/lib/codeFeatures.js +0 -3
- package/lib/codegen/common.d.ts +0 -12
- package/lib/codegen/common.js +0 -79
- package/lib/codegen/script/binding.d.ts +0 -4
- package/lib/codegen/script/binding.js +0 -41
- package/lib/codegen/template/camelized.d.ts +0 -2
- package/lib/codegen/template/camelized.js +0 -31
- package/lib/codegen/utils/src.d.ts +0 -2
- package/lib/codegen/utils/src.js +0 -19
- package/lib/plugins/vue-style-class-names.d.ts +0 -5
- package/lib/plugins/vue-style-class-names.js +0 -32
- package/lib/plugins/vue-style-reference-link.d.ts +0 -1
- package/lib/plugins/vue-style-reference-link.js +0 -3
- package/lib/plugins/vue-style-reference-links.d.ts +0 -3
- package/lib/plugins/vue-style-reference-links.js +0 -26
- package/lib/plugins/vue-vine.d.ts +0 -3
- package/lib/plugins/vue-vine.js +0 -35
- package/lib/utils/findDestructuredProps.d.ts +0 -1
- package/lib/utils/findDestructuredProps.js +0 -3
- package/lib/utils/parseCssImports.d.ts +0 -4
- package/lib/utils/parseCssImports.js +0 -19
|
@@ -12,6 +12,7 @@ const inlayHints_1 = require("../inlayHints");
|
|
|
12
12
|
const utils_1 = require("../utils");
|
|
13
13
|
const camelized_1 = require("../utils/camelized");
|
|
14
14
|
const unicode_1 = require("../utils/unicode");
|
|
15
|
+
const wrapWith_1 = require("../utils/wrapWith");
|
|
15
16
|
const elementDirectives_1 = require("./elementDirectives");
|
|
16
17
|
const elementEvents_1 = require("./elementEvents");
|
|
17
18
|
const interpolation_1 = require("./interpolation");
|
|
@@ -40,12 +41,12 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
|
|
|
40
41
|
&& prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
41
42
|
&& prop.arg.loc.source.startsWith('[')
|
|
42
43
|
&& prop.arg.loc.source.endsWith(']')) {
|
|
43
|
-
failedPropExps?.push({ node: prop.arg, prefix:
|
|
44
|
-
failedPropExps?.push({ node: prop.exp, prefix:
|
|
44
|
+
failedPropExps?.push({ node: prop.arg, prefix: `(`, suffix: `)` });
|
|
45
|
+
failedPropExps?.push({ node: prop.exp, prefix: `() => {`, suffix: `}` });
|
|
45
46
|
}
|
|
46
47
|
else if (!prop.arg
|
|
47
48
|
&& prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
48
|
-
failedPropExps?.push({ node: prop.exp, prefix:
|
|
49
|
+
failedPropExps?.push({ node: prop.exp, prefix: `(`, suffix: `)` });
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
52
|
}
|
|
@@ -66,7 +67,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
|
|
|
66
67
|
if (propName === undefined
|
|
67
68
|
|| options.vueCompilerOptions.dataAttributes.some(pattern => (0, minimatch_1.minimatch)(propName, pattern))) {
|
|
68
69
|
if (prop.exp && prop.exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY) {
|
|
69
|
-
failedPropExps?.push({ node: prop.exp, prefix:
|
|
70
|
+
failedPropExps?.push({ node: prop.exp, prefix: `(`, suffix: `)` });
|
|
70
71
|
}
|
|
71
72
|
continue;
|
|
72
73
|
}
|
|
@@ -80,14 +81,14 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
|
|
|
80
81
|
if (shouldSpread) {
|
|
81
82
|
yield `...{ `;
|
|
82
83
|
}
|
|
83
|
-
const codes = (0,
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
const codes = [...(0, wrapWith_1.wrapWith)(prop.loc.start.offset, prop.loc.end.offset, ctx.codeFeatures.verification, ...(prop.arg
|
|
85
|
+
? (0, objectProperty_1.generateObjectProperty)(options, ctx, propName, prop.arg.loc.start.offset, codeInfo, prop.loc.name_2 ??= {}, shouldCamelize)
|
|
86
|
+
: (0, wrapWith_1.wrapWith)(prop.loc.start.offset, prop.loc.start.offset + 'v-model'.length, ctx.codeFeatures.withoutHighlightAndCompletion, propName)), `: `, ...generatePropExp(options, ctx, prop, prop.exp, ctx.codeFeatures.all, enableCodeFeatures))];
|
|
86
87
|
if (enableCodeFeatures) {
|
|
87
88
|
yield* codes;
|
|
88
89
|
}
|
|
89
90
|
else {
|
|
90
|
-
yield (0, muggle_string_1.toString)(
|
|
91
|
+
yield (0, muggle_string_1.toString)(codes);
|
|
91
92
|
}
|
|
92
93
|
if (shouldSpread) {
|
|
93
94
|
yield ` }`;
|
|
@@ -99,12 +100,12 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
|
|
|
99
100
|
? `[__VLS_tryAsConstant(\`$\{${prop.arg.content}\}Modifiers\`)]`
|
|
100
101
|
: (0, shared_1.camelize)(propName) + `Modifiers`
|
|
101
102
|
: `modelModifiers`;
|
|
102
|
-
const codes = (0, elementDirectives_1.generateModifiers)(options, ctx, prop, propertyName);
|
|
103
|
+
const codes = [...(0, elementDirectives_1.generateModifiers)(options, ctx, prop, propertyName)];
|
|
103
104
|
if (enableCodeFeatures) {
|
|
104
105
|
yield* codes;
|
|
105
106
|
}
|
|
106
107
|
else {
|
|
107
|
-
yield (0, muggle_string_1.toString)(
|
|
108
|
+
yield (0, muggle_string_1.toString)(codes);
|
|
108
109
|
}
|
|
109
110
|
yield utils_1.newLine;
|
|
110
111
|
}
|
|
@@ -123,14 +124,14 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
|
|
|
123
124
|
if (shouldSpread) {
|
|
124
125
|
yield `...{ `;
|
|
125
126
|
}
|
|
126
|
-
const codes = (0,
|
|
127
|
-
|
|
128
|
-
|
|
127
|
+
const codes = [...(0, wrapWith_1.wrapWith)(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 ??= {}, shouldCamelize), `: `, ...(prop.value
|
|
128
|
+
? generateAttrValue(prop.value, ctx.codeFeatures.withoutNavigation)
|
|
129
|
+
: [`true`]))];
|
|
129
130
|
if (enableCodeFeatures) {
|
|
130
131
|
yield* codes;
|
|
131
132
|
}
|
|
132
133
|
else {
|
|
133
|
-
yield (0, muggle_string_1.toString)(
|
|
134
|
+
yield (0, muggle_string_1.toString)(codes);
|
|
134
135
|
}
|
|
135
136
|
if (shouldSpread) {
|
|
136
137
|
yield ` }`;
|
|
@@ -147,19 +148,19 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
|
|
|
147
148
|
}
|
|
148
149
|
}
|
|
149
150
|
else {
|
|
150
|
-
const codes = (0,
|
|
151
|
+
const codes = [...(0, wrapWith_1.wrapWith)(prop.exp.loc.start.offset, prop.exp.loc.end.offset, ctx.codeFeatures.verification, `...`, ...generatePropExp(options, ctx, prop, prop.exp, ctx.codeFeatures.all, enableCodeFeatures))];
|
|
151
152
|
if (enableCodeFeatures) {
|
|
152
153
|
yield* codes;
|
|
153
154
|
}
|
|
154
155
|
else {
|
|
155
|
-
yield (0, muggle_string_1.toString)(
|
|
156
|
+
yield (0, muggle_string_1.toString)(codes);
|
|
156
157
|
}
|
|
157
158
|
yield `,${utils_1.newLine}`;
|
|
158
159
|
}
|
|
159
160
|
}
|
|
160
161
|
}
|
|
161
162
|
}
|
|
162
|
-
function* generatePropExp(options, ctx, prop, exp, features, enableCodeFeatures) {
|
|
163
|
+
function* generatePropExp(options, ctx, prop, exp, features, enableCodeFeatures = true) {
|
|
163
164
|
const isShorthand = prop.arg?.loc.start.offset === prop.exp?.loc.start.offset;
|
|
164
165
|
if (isShorthand && features.completion) {
|
|
165
166
|
features = {
|
|
@@ -169,14 +170,14 @@ function* generatePropExp(options, ctx, prop, exp, features, enableCodeFeatures)
|
|
|
169
170
|
}
|
|
170
171
|
if (exp && exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY) { // style='z-index: 2' will compile to {'z-index':'2'}
|
|
171
172
|
if (!isShorthand) { // vue 3.4+
|
|
172
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', features, exp.loc.source, exp.loc.start.offset, exp.loc,
|
|
173
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', features, exp.loc.source, exp.loc.start.offset, exp.loc, `(`, `)`);
|
|
173
174
|
}
|
|
174
175
|
else {
|
|
175
176
|
const propVariableName = (0, shared_1.camelize)(exp.loc.source);
|
|
176
|
-
if (utils_1.
|
|
177
|
+
if (utils_1.identifierRegex.test(propVariableName)) {
|
|
177
178
|
const isDestructuredProp = options.destructuredPropNames?.has(propVariableName) ?? false;
|
|
178
179
|
const isTemplateRef = options.templateRefNames?.has(propVariableName) ?? false;
|
|
179
|
-
const codes = (0, camelized_1.generateCamelized)(exp.loc.source, exp.loc.start.offset, features);
|
|
180
|
+
const codes = (0, camelized_1.generateCamelized)(exp.loc.source, 'template', exp.loc.start.offset, features);
|
|
180
181
|
if (ctx.hasLocalVariable(propVariableName) || isDestructuredProp) {
|
|
181
182
|
yield* codes;
|
|
182
183
|
}
|
|
@@ -231,6 +232,8 @@ function getPropsCodeInfo(ctx, strictPropsCheck, shouldCamelize) {
|
|
|
231
232
|
},
|
|
232
233
|
verification: strictPropsCheck || {
|
|
233
234
|
shouldReport(_source, code) {
|
|
235
|
+
// https://typescript.tv/errors/#ts2353
|
|
236
|
+
// https://typescript.tv/errors/#ts2561
|
|
234
237
|
if (String(code) === '2353' || String(code) === '2561') {
|
|
235
238
|
return false;
|
|
236
239
|
}
|
|
@@ -5,6 +5,7 @@ exports.forEachElementNode = forEachElementNode;
|
|
|
5
5
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
6
6
|
const shared_1 = require("../../utils/shared");
|
|
7
7
|
const utils_1 = require("../utils");
|
|
8
|
+
const wrapWith_1 = require("../utils/wrapWith");
|
|
8
9
|
const context_1 = require("./context");
|
|
9
10
|
const objectProperty_1 = require("./objectProperty");
|
|
10
11
|
const styleScopedClasses_1 = require("./styleScopedClasses");
|
|
@@ -18,26 +19,35 @@ function* generateTemplate(options) {
|
|
|
18
19
|
ctx.addLocalVariable(options.propsAssignName);
|
|
19
20
|
}
|
|
20
21
|
const slotsPropertyName = (0, shared_1.getSlotsPropertyName)(options.vueCompilerOptions.target);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
if (options.vueCompilerOptions.inferTemplateDollarSlots) {
|
|
23
|
+
ctx.dollarVars.add(slotsPropertyName);
|
|
24
|
+
}
|
|
25
|
+
if (options.vueCompilerOptions.inferTemplateDollarAttrs) {
|
|
26
|
+
ctx.dollarVars.add('$attrs');
|
|
27
|
+
}
|
|
28
|
+
if (options.vueCompilerOptions.inferTemplateDollarRefs) {
|
|
29
|
+
ctx.dollarVars.add('$refs');
|
|
30
|
+
}
|
|
31
|
+
if (options.vueCompilerOptions.inferTemplateDollarEl) {
|
|
32
|
+
ctx.dollarVars.add('$el');
|
|
33
|
+
}
|
|
25
34
|
if (options.template.ast) {
|
|
26
35
|
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, options.template.ast, undefined);
|
|
27
36
|
}
|
|
28
37
|
yield* (0, styleScopedClasses_1.generateStyleScopedClassReferences)(ctx);
|
|
38
|
+
yield* ctx.generateAutoImportCompletion();
|
|
39
|
+
yield* ctx.generateHoistVariables();
|
|
29
40
|
const speicalTypes = [
|
|
30
41
|
[slotsPropertyName, yield* generateSlots(options, ctx)],
|
|
31
42
|
['$attrs', yield* generateInheritedAttrs(options, ctx)],
|
|
32
43
|
['$refs', yield* generateTemplateRefs(options, ctx)],
|
|
33
44
|
['$el', yield* generateRootEl(ctx)]
|
|
34
45
|
];
|
|
35
|
-
yield `var
|
|
46
|
+
yield `var __VLS_dollars!: {${utils_1.newLine}`;
|
|
36
47
|
for (const [name, type] of speicalTypes) {
|
|
37
48
|
yield `${name}: ${type}${utils_1.endOfLine}`;
|
|
38
49
|
}
|
|
39
|
-
yield `} & { [K in keyof
|
|
40
|
-
yield* ctx.generateAutoImportCompletion();
|
|
50
|
+
yield `} & { [K in keyof import('${options.vueCompilerOptions.lib}').ComponentPublicInstance]: unknown }${utils_1.endOfLine}`;
|
|
41
51
|
return ctx;
|
|
42
52
|
}
|
|
43
53
|
function* generateSlots(options, ctx) {
|
|
@@ -45,17 +55,15 @@ function* generateSlots(options, ctx) {
|
|
|
45
55
|
const name = (0, shared_1.getSlotsPropertyName)(options.vueCompilerOptions.target);
|
|
46
56
|
yield `type __VLS_Slots = __VLS_PrettifyGlobal<__VLS_OmitStringIndex<typeof __VLS_ctx.${name}>`;
|
|
47
57
|
for (const { expVar, propsVar } of ctx.dynamicSlots) {
|
|
48
|
-
ctx.hasSlot = true;
|
|
49
58
|
yield `${utils_1.newLine}& { [K in NonNullable<typeof ${expVar}>]?: (props: typeof ${propsVar}) => any }`;
|
|
50
59
|
}
|
|
51
60
|
for (const slot of ctx.slots) {
|
|
52
61
|
yield `${utils_1.newLine}& { `;
|
|
53
|
-
ctx.hasSlot = true;
|
|
54
62
|
if (slot.name && slot.offset !== undefined) {
|
|
55
63
|
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slot.name, slot.offset, ctx.codeFeatures.withoutHighlightAndCompletion, slot.nodeLoc);
|
|
56
64
|
}
|
|
57
65
|
else {
|
|
58
|
-
yield* (0,
|
|
66
|
+
yield* (0, wrapWith_1.wrapWith)(slot.tagRange[0], slot.tagRange[1], ctx.codeFeatures.withoutHighlightAndCompletion, `default`);
|
|
59
67
|
}
|
|
60
68
|
yield `?: (props: typeof ${slot.propsVar}) => any }`;
|
|
61
69
|
}
|
|
@@ -72,7 +80,7 @@ function* generateInheritedAttrs(options, ctx) {
|
|
|
72
80
|
if (ctx.bindingAttrLocs.length) {
|
|
73
81
|
yield `[`;
|
|
74
82
|
for (const loc of ctx.bindingAttrLocs) {
|
|
75
|
-
yield `
|
|
83
|
+
yield `__VLS_dollars.`;
|
|
76
84
|
yield [
|
|
77
85
|
loc.source,
|
|
78
86
|
'template',
|
|
@@ -87,16 +95,23 @@ function* generateInheritedAttrs(options, ctx) {
|
|
|
87
95
|
}
|
|
88
96
|
function* generateTemplateRefs(options, ctx) {
|
|
89
97
|
yield `type __VLS_TemplateRefs = {${utils_1.newLine}`;
|
|
90
|
-
for (const [name,
|
|
98
|
+
for (const [name, { typeExp, offset }] of ctx.templateRefs) {
|
|
91
99
|
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, name, offset, ctx.codeFeatures.navigationAndCompletion);
|
|
92
|
-
yield `:
|
|
100
|
+
yield `: ${typeExp},${utils_1.newLine}`;
|
|
93
101
|
}
|
|
94
102
|
yield `}${utils_1.endOfLine}`;
|
|
95
103
|
return `__VLS_TemplateRefs`;
|
|
96
104
|
}
|
|
97
105
|
function* generateRootEl(ctx) {
|
|
98
106
|
yield `type __VLS_RootEl = `;
|
|
99
|
-
|
|
107
|
+
if (ctx.singleRootElTypes.length && !ctx.singleRootNodes.has(null)) {
|
|
108
|
+
for (const type of ctx.singleRootElTypes) {
|
|
109
|
+
yield `${utils_1.newLine}| ${type}`;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
yield `any`;
|
|
114
|
+
}
|
|
100
115
|
yield utils_1.endOfLine;
|
|
101
116
|
return `__VLS_RootEl`;
|
|
102
117
|
}
|
|
@@ -87,7 +87,7 @@ function* forEachInterpolationSegment(ts, destructuredPropNames, templateRefName
|
|
|
87
87
|
for (let i = 0; i < ctxVars.length - 1; i++) {
|
|
88
88
|
const curVar = ctxVars[i];
|
|
89
89
|
const nextVar = ctxVars[i + 1];
|
|
90
|
-
yield* generateVar(code, ctx.
|
|
90
|
+
yield* generateVar(code, ctx.dollarVars, destructuredPropNames, templateRefNames, curVar);
|
|
91
91
|
if (nextVar.isShorthand) {
|
|
92
92
|
yield [code.slice(curVar.offset + curVar.text.length, nextVar.offset + nextVar.text.length), curVar.offset + curVar.text.length];
|
|
93
93
|
yield [': ', undefined];
|
|
@@ -97,7 +97,7 @@ function* forEachInterpolationSegment(ts, destructuredPropNames, templateRefName
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
const lastVar = ctxVars.at(-1);
|
|
100
|
-
yield* generateVar(code, ctx.
|
|
100
|
+
yield* generateVar(code, ctx.dollarVars, destructuredPropNames, templateRefNames, lastVar);
|
|
101
101
|
if (lastVar.offset + lastVar.text.length < code.length) {
|
|
102
102
|
yield [code.slice(lastVar.offset + lastVar.text.length), lastVar.offset + lastVar.text.length, 'endText'];
|
|
103
103
|
}
|
|
@@ -106,7 +106,7 @@ function* forEachInterpolationSegment(ts, destructuredPropNames, templateRefName
|
|
|
106
106
|
yield [code, 0];
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
|
-
function* generateVar(code,
|
|
109
|
+
function* generateVar(code, dollarVars, destructuredPropNames, templateRefNames, curVar) {
|
|
110
110
|
// fix https://github.com/vuejs/language-tools/issues/1205
|
|
111
111
|
// fix https://github.com/vuejs/language-tools/issues/1264
|
|
112
112
|
yield ['', curVar.offset, 'errorMappingOnly'];
|
|
@@ -118,8 +118,8 @@ function* generateVar(code, specialVars, destructuredPropNames, templateRefNames
|
|
|
118
118
|
yield [`)`, undefined];
|
|
119
119
|
}
|
|
120
120
|
else {
|
|
121
|
-
if (
|
|
122
|
-
yield [`
|
|
121
|
+
if (dollarVars.has(curVar.text)) {
|
|
122
|
+
yield [`__VLS_dollars.`, undefined];
|
|
123
123
|
}
|
|
124
124
|
else if (!isDestructuredProp) {
|
|
125
125
|
yield [`__VLS_ctx.`, undefined];
|
|
@@ -5,6 +5,7 @@ const shared_1 = require("@vue/shared");
|
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
6
|
const camelized_1 = require("../utils/camelized");
|
|
7
7
|
const stringLiteralKey_1 = require("../utils/stringLiteralKey");
|
|
8
|
+
const wrapWith_1 = require("../utils/wrapWith");
|
|
8
9
|
const interpolation_1 = require("./interpolation");
|
|
9
10
|
function* generateObjectProperty(options, ctx, code, offset, features, astHolder, shouldCamelize = false, shouldBeConstant = false) {
|
|
10
11
|
if (code.startsWith('[') && code.endsWith(']') && astHolder) {
|
|
@@ -16,15 +17,15 @@ function* generateObjectProperty(options, ctx, code, offset, features, astHolder
|
|
|
16
17
|
}
|
|
17
18
|
}
|
|
18
19
|
else if (shouldCamelize) {
|
|
19
|
-
if (utils_1.
|
|
20
|
-
yield* (0, camelized_1.generateCamelized)(code, offset, features);
|
|
20
|
+
if (utils_1.identifierRegex.test((0, shared_1.camelize)(code))) {
|
|
21
|
+
yield* (0, camelized_1.generateCamelized)(code, 'template', offset, features);
|
|
21
22
|
}
|
|
22
23
|
else {
|
|
23
|
-
yield* (0,
|
|
24
|
+
yield* (0, wrapWith_1.wrapWith)(offset, offset + code.length, features, `'`, ...(0, camelized_1.generateCamelized)(code, 'template', offset, utils_1.combineLastMapping), `'`);
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
else {
|
|
27
|
-
if (utils_1.
|
|
28
|
+
if (utils_1.identifierRegex.test(code)) {
|
|
28
29
|
yield [code, 'template', offset, features];
|
|
29
30
|
}
|
|
30
31
|
else {
|
|
@@ -5,7 +5,7 @@ const utils_1 = require("../utils");
|
|
|
5
5
|
const stringLiteralKey_1 = require("../utils/stringLiteralKey");
|
|
6
6
|
const interpolation_1 = require("./interpolation");
|
|
7
7
|
function* generatePropertyAccess(options, ctx, code, offset, features, astHolder) {
|
|
8
|
-
if (!options.compilerOptions.noPropertyAccessFromIndexSignature && utils_1.
|
|
8
|
+
if (!options.compilerOptions.noPropertyAccessFromIndexSignature && utils_1.identifierRegex.test(code)) {
|
|
9
9
|
yield `.`;
|
|
10
10
|
yield offset !== undefined && features
|
|
11
11
|
? [code, 'template', offset, features]
|
|
@@ -4,12 +4,14 @@ exports.generateSlotOutlet = generateSlotOutlet;
|
|
|
4
4
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
5
5
|
const inlayHints_1 = require("../inlayHints");
|
|
6
6
|
const utils_1 = require("../utils");
|
|
7
|
+
const wrapWith_1 = require("../utils/wrapWith");
|
|
7
8
|
const elementChildren_1 = require("./elementChildren");
|
|
8
9
|
const elementProps_1 = require("./elementProps");
|
|
9
10
|
const interpolation_1 = require("./interpolation");
|
|
10
11
|
const propertyAccess_1 = require("./propertyAccess");
|
|
11
12
|
function* generateSlotOutlet(options, ctx, node) {
|
|
12
13
|
const startTagOffset = node.loc.start.offset + options.template.content.slice(node.loc.start.offset).indexOf(node.tag);
|
|
14
|
+
const startTagEndOffset = startTagOffset + node.tag.length;
|
|
13
15
|
const propsVar = ctx.getInternalVariable();
|
|
14
16
|
const nameProp = node.props.find(prop => {
|
|
15
17
|
if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE) {
|
|
@@ -22,7 +24,7 @@ function* generateSlotOutlet(options, ctx, node) {
|
|
|
22
24
|
}
|
|
23
25
|
});
|
|
24
26
|
if (options.hasDefineSlots) {
|
|
25
|
-
yield `
|
|
27
|
+
yield `__VLS_asFunctionalSlot(`;
|
|
26
28
|
if (nameProp) {
|
|
27
29
|
let codes;
|
|
28
30
|
if (nameProp.type === CompilerDOM.NodeTypes.ATTRIBUTE && nameProp.value) {
|
|
@@ -37,20 +39,20 @@ function* generateSlotOutlet(options, ctx, node) {
|
|
|
37
39
|
&& nameProp.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
38
40
|
codes = [
|
|
39
41
|
`[`,
|
|
40
|
-
...(0, elementProps_1.generatePropExp)(options, ctx, nameProp, nameProp.exp, ctx.codeFeatures.all
|
|
42
|
+
...(0, elementProps_1.generatePropExp)(options, ctx, nameProp, nameProp.exp, ctx.codeFeatures.all),
|
|
41
43
|
`]`
|
|
42
44
|
];
|
|
43
45
|
}
|
|
44
46
|
else {
|
|
45
47
|
codes = [`['default']`];
|
|
46
48
|
}
|
|
47
|
-
yield* (0,
|
|
49
|
+
yield* (0, wrapWith_1.wrapWith)(nameProp.loc.start.offset, nameProp.loc.end.offset, ctx.codeFeatures.verification, `${options.slotsAssignName ?? '__VLS_slots'}`, ...codes);
|
|
48
50
|
}
|
|
49
51
|
else {
|
|
50
|
-
yield* (0,
|
|
52
|
+
yield* (0, wrapWith_1.wrapWith)(startTagOffset, startTagEndOffset, ctx.codeFeatures.verification, `${options.slotsAssignName ?? '__VLS_slots'}[`, ...(0, wrapWith_1.wrapWith)(startTagOffset, startTagEndOffset, ctx.codeFeatures.verification, `'default'`), `]`);
|
|
51
53
|
}
|
|
52
|
-
yield `)
|
|
53
|
-
yield* (0,
|
|
54
|
+
yield `)(`;
|
|
55
|
+
yield* (0, wrapWith_1.wrapWith)(startTagOffset, startTagEndOffset, ctx.codeFeatures.verification, `{${utils_1.newLine}`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, node.props.filter(prop => prop !== nameProp), true, true), `}`);
|
|
54
56
|
yield `)${utils_1.endOfLine}`;
|
|
55
57
|
}
|
|
56
58
|
else {
|
|
@@ -64,7 +66,7 @@ function* generateSlotOutlet(options, ctx, node) {
|
|
|
64
66
|
offset: nameProp.loc.start.offset + nameProp.loc.source.indexOf(nameProp.value.content, nameProp.name.length),
|
|
65
67
|
tagRange: [startTagOffset, startTagOffset + node.tag.length],
|
|
66
68
|
nodeLoc: node.loc,
|
|
67
|
-
propsVar,
|
|
69
|
+
propsVar: ctx.getHoistVariable(propsVar),
|
|
68
70
|
});
|
|
69
71
|
}
|
|
70
72
|
else if (nameProp?.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
@@ -78,16 +80,16 @@ function* generateSlotOutlet(options, ctx, node) {
|
|
|
78
80
|
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, nameProp.exp.content, nameProp.exp.loc.start.offset, nameProp.exp);
|
|
79
81
|
yield `)${utils_1.endOfLine}`;
|
|
80
82
|
ctx.dynamicSlots.push({
|
|
81
|
-
expVar,
|
|
82
|
-
propsVar,
|
|
83
|
+
expVar: ctx.getHoistVariable(expVar),
|
|
84
|
+
propsVar: ctx.getHoistVariable(propsVar),
|
|
83
85
|
});
|
|
84
86
|
}
|
|
85
87
|
else {
|
|
86
88
|
ctx.slots.push({
|
|
87
89
|
name: 'default',
|
|
88
|
-
tagRange: [startTagOffset,
|
|
90
|
+
tagRange: [startTagOffset, startTagEndOffset],
|
|
89
91
|
nodeLoc: node.loc,
|
|
90
|
-
propsVar,
|
|
92
|
+
propsVar: ctx.getHoistVariable(propsVar),
|
|
91
93
|
});
|
|
92
94
|
}
|
|
93
95
|
}
|
|
@@ -5,74 +5,24 @@ exports.collectStyleScopedClassReferences = collectStyleScopedClassReferences;
|
|
|
5
5
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
6
6
|
const scriptSetupRanges_1 = require("../../parsers/scriptSetupRanges");
|
|
7
7
|
const utils_1 = require("../utils");
|
|
8
|
+
const escaped_1 = require("../utils/escaped");
|
|
9
|
+
const wrapWith_1 = require("../utils/wrapWith");
|
|
10
|
+
const classNameEscapeRegex = /([\\'])/;
|
|
8
11
|
function* generateStyleScopedClassReferences(ctx, withDot = false) {
|
|
9
|
-
if (!ctx.emptyClassOffsets.length && !ctx.scopedClasses.length) {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
yield `[`;
|
|
13
12
|
for (const offset of ctx.emptyClassOffsets) {
|
|
14
|
-
yield
|
|
13
|
+
yield `/** @type {__VLS_StyleScopedClasses['`;
|
|
15
14
|
yield [
|
|
16
15
|
'',
|
|
17
16
|
'template',
|
|
18
17
|
offset,
|
|
19
18
|
ctx.codeFeatures.additionalCompletion,
|
|
20
19
|
];
|
|
21
|
-
yield `'
|
|
20
|
+
yield `']} */${utils_1.endOfLine}`;
|
|
22
21
|
}
|
|
23
22
|
for (const { source, className, offset } of ctx.scopedClasses) {
|
|
24
|
-
yield [
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
offset - (withDot ? 1 : 0),
|
|
28
|
-
ctx.codeFeatures.navigation,
|
|
29
|
-
];
|
|
30
|
-
yield `'`;
|
|
31
|
-
// fix https://github.com/vuejs/language-tools/issues/4537
|
|
32
|
-
yield* escapeString(source, className, offset, ['\\', '\'']);
|
|
33
|
-
yield `'`;
|
|
34
|
-
yield [
|
|
35
|
-
'',
|
|
36
|
-
source,
|
|
37
|
-
offset + className.length,
|
|
38
|
-
ctx.codeFeatures.navigationWithoutRename,
|
|
39
|
-
];
|
|
40
|
-
yield `, `;
|
|
41
|
-
}
|
|
42
|
-
yield `] as (keyof __VLS_StyleScopedClasses)[]${utils_1.endOfLine}`;
|
|
43
|
-
function* escapeString(source, className, offset, escapeTargets) {
|
|
44
|
-
let count = 0;
|
|
45
|
-
const currentEscapeTargets = [...escapeTargets];
|
|
46
|
-
const firstEscapeTarget = currentEscapeTargets.shift();
|
|
47
|
-
const splitted = className.split(firstEscapeTarget);
|
|
48
|
-
for (let i = 0; i < splitted.length; i++) {
|
|
49
|
-
const part = splitted[i];
|
|
50
|
-
const partLength = part.length;
|
|
51
|
-
if (escapeTargets.length > 0) {
|
|
52
|
-
yield* escapeString(source, part, offset + count, [...currentEscapeTargets]);
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
yield [
|
|
56
|
-
part,
|
|
57
|
-
source,
|
|
58
|
-
offset + count,
|
|
59
|
-
ctx.codeFeatures.navigationAndAdditionalCompletion,
|
|
60
|
-
];
|
|
61
|
-
}
|
|
62
|
-
if (i !== splitted.length - 1) {
|
|
63
|
-
yield '\\';
|
|
64
|
-
yield [
|
|
65
|
-
firstEscapeTarget,
|
|
66
|
-
source,
|
|
67
|
-
offset + count + partLength,
|
|
68
|
-
ctx.codeFeatures.navigationAndAdditionalCompletion,
|
|
69
|
-
];
|
|
70
|
-
count += partLength + 1;
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
count += partLength;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
23
|
+
yield `/** @type {__VLS_StyleScopedClasses[`;
|
|
24
|
+
yield* (0, wrapWith_1.wrapWith)(offset - (withDot ? 1 : 0), offset + className.length, source, ctx.codeFeatures.navigation, `'`, ...(0, escaped_1.generateEscaped)(className, source, offset, ctx.codeFeatures.navigationAndAdditionalCompletion, classNameEscapeRegex), `'`);
|
|
25
|
+
yield `]} */${utils_1.endOfLine}`;
|
|
76
26
|
}
|
|
77
27
|
}
|
|
78
28
|
function collectStyleScopedClassReferences(options, ctx, node) {
|
|
@@ -4,6 +4,7 @@ exports.generateTemplateChild = generateTemplateChild;
|
|
|
4
4
|
exports.getVForNode = getVForNode;
|
|
5
5
|
exports.parseInterpolationNode = parseInterpolationNode;
|
|
6
6
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
7
|
+
const shared_1 = require("../../utils/shared");
|
|
7
8
|
const utils_1 = require("../utils");
|
|
8
9
|
const element_1 = require("./element");
|
|
9
10
|
const interpolation_1 = require("./interpolation");
|
|
@@ -11,6 +12,7 @@ const slotOutlet_1 = require("./slotOutlet");
|
|
|
11
12
|
const vFor_1 = require("./vFor");
|
|
12
13
|
const vIf_1 = require("./vIf");
|
|
13
14
|
const vSlot_1 = require("./vSlot");
|
|
15
|
+
const commentDirectiveRegex = /^<!--\s*@vue-(?<name>[-\w]+)\b(?<content>[\s\S]*)-->$/;
|
|
14
16
|
// @ts-ignore
|
|
15
17
|
const transformContext = {
|
|
16
18
|
onError: () => { },
|
|
@@ -28,38 +30,44 @@ const transformContext = {
|
|
|
28
30
|
};
|
|
29
31
|
function* generateTemplateChild(options, ctx, node, prevNode, isVForChild = false) {
|
|
30
32
|
if (prevNode?.type === CompilerDOM.NodeTypes.COMMENT) {
|
|
31
|
-
const
|
|
32
|
-
if (
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
33
|
+
const match = prevNode.loc.source.match(commentDirectiveRegex);
|
|
34
|
+
if (match) {
|
|
35
|
+
const { name, content } = match.groups;
|
|
36
|
+
switch (name) {
|
|
37
|
+
case 'skip': {
|
|
38
|
+
yield `// @vue-skip${utils_1.newLine}`;
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
case 'ignore': {
|
|
42
|
+
yield* ctx.ignoreError();
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
case 'expect-error': {
|
|
46
|
+
yield* ctx.expectError(prevNode);
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
case 'generic': {
|
|
50
|
+
const text = content.trim();
|
|
51
|
+
if (text.startsWith('{') && text.endsWith('}')) {
|
|
52
|
+
ctx.lastGenericComment = {
|
|
53
|
+
content: text.slice(1, -1),
|
|
54
|
+
offset: prevNode.loc.start.offset + prevNode.loc.source.indexOf('{') + 1,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
50
59
|
}
|
|
51
60
|
}
|
|
52
61
|
}
|
|
53
|
-
const shouldInheritRootNodeAttrs = options.inheritAttrs;
|
|
54
62
|
const cur = node;
|
|
55
63
|
if (cur.codegenNode?.type === CompilerDOM.NodeTypes.JS_CACHE_EXPRESSION) {
|
|
56
64
|
cur.codegenNode = cur.codegenNode.value;
|
|
57
65
|
}
|
|
58
66
|
if (node.type === CompilerDOM.NodeTypes.ROOT) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
ctx.singleRootNode = node.children[0];
|
|
67
|
+
for (const item of collectSingleRootNodes(options, node.children)) {
|
|
68
|
+
ctx.singleRootNodes.add(item);
|
|
62
69
|
}
|
|
70
|
+
let prev;
|
|
63
71
|
for (const childNode of node.children) {
|
|
64
72
|
yield* generateTemplateChild(options, ctx, childNode, prev);
|
|
65
73
|
prev = childNode;
|
|
@@ -91,7 +99,7 @@ function* generateTemplateChild(options, ctx, node, prevNode, isVForChild = fals
|
|
|
91
99
|
}
|
|
92
100
|
else {
|
|
93
101
|
const { currentComponent } = ctx;
|
|
94
|
-
yield* (0, element_1.generateComponent)(options, ctx, node);
|
|
102
|
+
yield* (0, element_1.generateComponent)(options, ctx, node, isVForChild);
|
|
95
103
|
ctx.currentComponent = currentComponent;
|
|
96
104
|
}
|
|
97
105
|
}
|
|
@@ -126,6 +134,30 @@ function* generateTemplateChild(options, ctx, node, prevNode, isVForChild = fals
|
|
|
126
134
|
// not needed progress
|
|
127
135
|
}
|
|
128
136
|
}
|
|
137
|
+
function* collectSingleRootNodes(options, children) {
|
|
138
|
+
if (children.length !== 1) {
|
|
139
|
+
// "null" is used to determine whether the component is not always has a single root
|
|
140
|
+
if (children.length > 1) {
|
|
141
|
+
yield null;
|
|
142
|
+
}
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const child = children[0];
|
|
146
|
+
if (child.type === CompilerDOM.NodeTypes.IF) {
|
|
147
|
+
for (const branch of child.branches) {
|
|
148
|
+
yield* collectSingleRootNodes(options, branch.children);
|
|
149
|
+
}
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
else if (child.type !== CompilerDOM.NodeTypes.ELEMENT) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
yield child;
|
|
156
|
+
const tag = (0, shared_1.hyphenateTag)(child.tag);
|
|
157
|
+
if (options.vueCompilerOptions.fallthroughComponentNames.includes(tag)) {
|
|
158
|
+
yield* collectSingleRootNodes(options, child.children);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
129
161
|
// TODO: track https://github.com/vuejs/vue-next/issues/3498
|
|
130
162
|
function getVForNode(node) {
|
|
131
163
|
const forDirective = node.props.find((prop) => prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
@@ -146,11 +178,11 @@ function getVForNode(node) {
|
|
|
146
178
|
}
|
|
147
179
|
}
|
|
148
180
|
function getVIfNode(node) {
|
|
149
|
-
const
|
|
181
|
+
const ifDirective = node.props.find((prop) => prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
150
182
|
&& prop.name === 'if');
|
|
151
|
-
if (
|
|
183
|
+
if (ifDirective) {
|
|
152
184
|
let ifNode;
|
|
153
|
-
CompilerDOM.processIf(node,
|
|
185
|
+
CompilerDOM.processIf(node, ifDirective, transformContext, _ifNode => {
|
|
154
186
|
ifNode = { ..._ifNode };
|
|
155
187
|
return undefined;
|
|
156
188
|
});
|
|
@@ -158,7 +190,7 @@ function getVIfNode(node) {
|
|
|
158
190
|
for (const branch of ifNode.branches) {
|
|
159
191
|
branch.children = [{
|
|
160
192
|
...node,
|
|
161
|
-
props: node.props.filter(prop => prop !==
|
|
193
|
+
props: node.props.filter(prop => prop !== ifDirective),
|
|
162
194
|
}];
|
|
163
195
|
}
|
|
164
196
|
return ifNode;
|
|
@@ -24,7 +24,7 @@ function* generateVFor(options, ctx, node) {
|
|
|
24
24
|
yield `] of `;
|
|
25
25
|
if (source.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
26
26
|
yield `__VLS_getVForSourceType(`;
|
|
27
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, source.content, source.loc.start.offset, source.loc,
|
|
27
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, source.content, source.loc.start.offset, source.loc, `(`, `)`);
|
|
28
28
|
yield `!)`; // #3102
|
|
29
29
|
}
|
|
30
30
|
else {
|
|
@@ -46,7 +46,7 @@ function* generateVFor(options, ctx, node) {
|
|
|
46
46
|
for (const prop of argument.returns.props.properties) {
|
|
47
47
|
if (prop.value.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
48
48
|
&& !prop.value.isStatic) {
|
|
49
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, prop.value.content, prop.value.loc.start.offset, prop.value.loc,
|
|
49
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, prop.value.content, prop.value.loc.start.offset, prop.value.loc, `(`, `)`);
|
|
50
50
|
yield utils_1.endOfLine;
|
|
51
51
|
}
|
|
52
52
|
}
|