@vue/language-core 3.0.0-beta.1 → 3.0.0-beta.3
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/codeFeatures.d.ts +5 -1
- package/lib/codegen/codeFeatures.js +3 -1
- package/lib/codegen/globalTypes.js +1 -1
- package/lib/codegen/localTypes.js +1 -1
- package/lib/codegen/script/scriptSetup.js +19 -19
- package/lib/codegen/script/template.js +0 -1
- package/lib/codegen/style/classProperty.js +1 -1
- package/lib/codegen/style/imports.js +2 -2
- package/lib/codegen/style/scopedClasses.js +1 -1
- package/lib/codegen/template/context.d.ts +1 -1
- package/lib/codegen/template/context.js +1 -1
- package/lib/codegen/template/element.js +6 -8
- package/lib/codegen/template/elementDirectives.js +1 -1
- package/lib/codegen/template/elementEvents.js +10 -9
- package/lib/codegen/template/elementProps.js +4 -4
- package/lib/codegen/template/index.js +3 -3
- package/lib/codegen/template/interpolation.d.ts +3 -6
- package/lib/codegen/template/interpolation.js +6 -4
- package/lib/codegen/template/objectProperty.d.ts +1 -1
- package/lib/codegen/template/objectProperty.js +4 -4
- package/lib/codegen/template/propertyAccess.d.ts +1 -1
- package/lib/codegen/template/propertyAccess.js +2 -2
- package/lib/codegen/template/slotOutlet.js +2 -2
- package/lib/codegen/template/styleScopedClasses.js +2 -2
- package/lib/codegen/template/templateChild.js +1 -1
- package/lib/codegen/template/vFor.js +3 -3
- package/lib/codegen/template/vIf.js +1 -1
- package/lib/codegen/template/vSlot.js +2 -2
- package/lib/codegen/utils/index.d.ts +1 -1
- package/lib/codegen/utils/index.js +8 -5
- package/lib/parsers/scriptSetupRanges.js +10 -10
- package/lib/plugins/file-html.js +3 -3
- package/lib/plugins/file-md.js +4 -4
- package/lib/plugins/vue-template-inline-ts.js +2 -2
- package/lib/plugins/vue-tsx.d.ts +1 -1
- package/lib/utils/parseSfc.js +3 -3
- package/lib/utils/ts.js +9 -9
- package/lib/virtualFile/computedSfc.js +22 -1
- package/package.json +2 -2
|
@@ -6,7 +6,6 @@ declare const raw: {
|
|
|
6
6
|
semantic: true;
|
|
7
7
|
navigation: true;
|
|
8
8
|
};
|
|
9
|
-
none: {};
|
|
10
9
|
verification: {
|
|
11
10
|
verification: true;
|
|
12
11
|
};
|
|
@@ -50,6 +49,11 @@ declare const raw: {
|
|
|
50
49
|
completion: true;
|
|
51
50
|
semantic: true;
|
|
52
51
|
};
|
|
52
|
+
semanticWithoutHighlight: {
|
|
53
|
+
semantic: {
|
|
54
|
+
shouldHighlight: () => false;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
53
57
|
withoutHighlight: {
|
|
54
58
|
semantic: {
|
|
55
59
|
shouldHighlight: () => false;
|
|
@@ -8,7 +8,6 @@ const raw = {
|
|
|
8
8
|
semantic: true,
|
|
9
9
|
navigation: true,
|
|
10
10
|
},
|
|
11
|
-
none: {},
|
|
12
11
|
verification: {
|
|
13
12
|
verification: true,
|
|
14
13
|
},
|
|
@@ -46,6 +45,9 @@ const raw = {
|
|
|
46
45
|
completion: true,
|
|
47
46
|
semantic: true,
|
|
48
47
|
},
|
|
48
|
+
semanticWithoutHighlight: {
|
|
49
|
+
semantic: { shouldHighlight: () => false },
|
|
50
|
+
},
|
|
49
51
|
withoutHighlight: {
|
|
50
52
|
semantic: { shouldHighlight: () => false },
|
|
51
53
|
verification: true,
|
|
@@ -123,7 +123,7 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
|
|
|
123
123
|
type __VLS_ResolveDirectives<T> = {
|
|
124
124
|
[K in Exclude<keyof T, keyof __VLS_GlobalDirectives> & string as \`v\${Capitalize<K>}\`]: T[K];
|
|
125
125
|
};
|
|
126
|
-
type __VLS_PrettifyGlobal<T> = { [K in keyof T]: T[K]; } & {};
|
|
126
|
+
type __VLS_PrettifyGlobal<T> = { [K in keyof T as K]: T[K]; } & {};
|
|
127
127
|
type __VLS_UseTemplateRef<T> = Readonly<import('${lib}').ShallowRef<T | null>>;
|
|
128
128
|
|
|
129
129
|
function __VLS_getVForSourceType<T extends number | string | any[] | Iterable<any>>(source: T): [
|
|
@@ -16,7 +16,7 @@ type __VLS_WithDefaults<P, D> = {
|
|
|
16
16
|
: P[K]
|
|
17
17
|
};
|
|
18
18
|
`.trimStart());
|
|
19
|
-
const PrettifyLocal = defineHelper(`__VLS_PrettifyLocal`, () => `type __VLS_PrettifyLocal<T> = { [K in keyof T]: T[K]; } & {}${utils_1.endOfLine}`);
|
|
19
|
+
const PrettifyLocal = defineHelper(`__VLS_PrettifyLocal`, () => `type __VLS_PrettifyLocal<T> = { [K in keyof T as K]: T[K]; } & {}${utils_1.endOfLine}`);
|
|
20
20
|
const WithSlots = defineHelper(`__VLS_WithSlots`, () => `
|
|
21
21
|
type __VLS_WithSlots<T, S> = T & {
|
|
22
22
|
new(): {
|
|
@@ -135,11 +135,11 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
|
|
|
135
135
|
setupCodeModifies.push([
|
|
136
136
|
[`(`],
|
|
137
137
|
callExp.start,
|
|
138
|
-
callExp.start
|
|
138
|
+
callExp.start,
|
|
139
139
|
], [
|
|
140
140
|
[` as typeof __VLS_dollars.$attrs)`],
|
|
141
141
|
callExp.end,
|
|
142
|
-
callExp.end
|
|
142
|
+
callExp.end,
|
|
143
143
|
]);
|
|
144
144
|
}
|
|
145
145
|
}
|
|
@@ -147,25 +147,25 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
|
|
|
147
147
|
setupCodeModifies.push([
|
|
148
148
|
[`(`],
|
|
149
149
|
callExp.start,
|
|
150
|
-
callExp.start
|
|
150
|
+
callExp.start,
|
|
151
151
|
], [
|
|
152
152
|
arg ? [
|
|
153
153
|
` as Omit<__VLS_StyleModules, '$style'>[`,
|
|
154
154
|
(0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.all),
|
|
155
|
-
`])
|
|
155
|
+
`])`,
|
|
156
156
|
] : [
|
|
157
157
|
` as __VLS_StyleModules[`,
|
|
158
158
|
...(0, wrapWith_1.wrapWith)(exp.start, exp.end, scriptSetup.name, codeFeatures_1.codeFeatures.verification, `'$style'`),
|
|
159
|
-
`])
|
|
159
|
+
`])`,
|
|
160
160
|
],
|
|
161
161
|
callExp.end,
|
|
162
|
-
callExp.end
|
|
162
|
+
callExp.end,
|
|
163
163
|
]);
|
|
164
164
|
if (arg) {
|
|
165
165
|
setupCodeModifies.push([
|
|
166
166
|
[`__VLS_placeholder`],
|
|
167
167
|
arg.start,
|
|
168
|
-
arg.end
|
|
168
|
+
arg.end,
|
|
169
169
|
]);
|
|
170
170
|
}
|
|
171
171
|
}
|
|
@@ -174,11 +174,11 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
|
|
|
174
174
|
setupCodeModifies.push([
|
|
175
175
|
[`(`],
|
|
176
176
|
callExp.start,
|
|
177
|
-
callExp.start
|
|
177
|
+
callExp.start,
|
|
178
178
|
], [
|
|
179
179
|
[` as typeof __VLS_dollars.$slots)`],
|
|
180
180
|
callExp.end,
|
|
181
|
-
callExp.end
|
|
181
|
+
callExp.end,
|
|
182
182
|
]);
|
|
183
183
|
}
|
|
184
184
|
}
|
|
@@ -188,7 +188,7 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
|
|
|
188
188
|
? [
|
|
189
189
|
`__VLS_TemplateRefs[`,
|
|
190
190
|
(0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.withoutSemantic),
|
|
191
|
-
`]
|
|
191
|
+
`]`,
|
|
192
192
|
]
|
|
193
193
|
: [`unknown`];
|
|
194
194
|
if (isTs) {
|
|
@@ -196,32 +196,32 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
|
|
|
196
196
|
[
|
|
197
197
|
`<`,
|
|
198
198
|
...templateRefType,
|
|
199
|
-
|
|
199
|
+
`>`,
|
|
200
200
|
],
|
|
201
201
|
exp.end,
|
|
202
|
-
exp.end
|
|
202
|
+
exp.end,
|
|
203
203
|
]);
|
|
204
204
|
}
|
|
205
205
|
else {
|
|
206
206
|
setupCodeModifies.push([
|
|
207
207
|
[`(`],
|
|
208
208
|
callExp.start,
|
|
209
|
-
callExp.start
|
|
209
|
+
callExp.start,
|
|
210
210
|
], [
|
|
211
211
|
[
|
|
212
212
|
` as __VLS_UseTemplateRef<`,
|
|
213
213
|
...templateRefType,
|
|
214
|
-
`>)
|
|
214
|
+
`>)`,
|
|
215
215
|
],
|
|
216
216
|
callExp.end,
|
|
217
|
-
callExp.end
|
|
217
|
+
callExp.end,
|
|
218
218
|
]);
|
|
219
219
|
}
|
|
220
220
|
if (arg) {
|
|
221
221
|
setupCodeModifies.push([
|
|
222
222
|
[`__VLS_placeholder`],
|
|
223
223
|
arg.start,
|
|
224
|
-
arg.end
|
|
224
|
+
arg.end,
|
|
225
225
|
]);
|
|
226
226
|
}
|
|
227
227
|
}
|
|
@@ -291,13 +291,13 @@ function* generateDefineWithType(scriptSetup, statement, callExp, typeArg, name,
|
|
|
291
291
|
else if (typeArg) {
|
|
292
292
|
yield [[
|
|
293
293
|
`const ${defaultName} = `,
|
|
294
|
-
(0, utils_1.generateSfcBlockSection)(scriptSetup, callExp.start, typeArg.start, codeFeatures_1.codeFeatures.all)
|
|
294
|
+
(0, utils_1.generateSfcBlockSection)(scriptSetup, callExp.start, typeArg.start, codeFeatures_1.codeFeatures.all),
|
|
295
295
|
], statement.start, typeArg.start];
|
|
296
296
|
yield [[
|
|
297
297
|
(0, utils_1.generateSfcBlockSection)(scriptSetup, typeArg.end, callExp.end, codeFeatures_1.codeFeatures.all),
|
|
298
298
|
utils_1.endOfLine,
|
|
299
299
|
(0, utils_1.generateSfcBlockSection)(scriptSetup, statement.start, callExp.start, codeFeatures_1.codeFeatures.all),
|
|
300
|
-
defaultName
|
|
300
|
+
defaultName,
|
|
301
301
|
], typeArg.end, callExp.end];
|
|
302
302
|
}
|
|
303
303
|
else {
|
|
@@ -306,7 +306,7 @@ function* generateDefineWithType(scriptSetup, statement, callExp, typeArg, name,
|
|
|
306
306
|
(0, utils_1.generateSfcBlockSection)(scriptSetup, callExp.start, callExp.end, codeFeatures_1.codeFeatures.all),
|
|
307
307
|
utils_1.endOfLine,
|
|
308
308
|
(0, utils_1.generateSfcBlockSection)(scriptSetup, statement.start, callExp.start, codeFeatures_1.codeFeatures.all),
|
|
309
|
-
defaultName
|
|
309
|
+
defaultName,
|
|
310
310
|
], statement.start, callExp.end];
|
|
311
311
|
}
|
|
312
312
|
}
|
|
@@ -103,7 +103,6 @@ function* generateTemplateBody(options, templateCodegenCtx) {
|
|
|
103
103
|
yield* options.templateCodegen.codes;
|
|
104
104
|
}
|
|
105
105
|
else {
|
|
106
|
-
yield `// no template${utils_1.newLine}`;
|
|
107
106
|
if (!options.scriptSetupRanges?.defineSlots) {
|
|
108
107
|
yield `type __VLS_Slots = {}${utils_1.endOfLine}`;
|
|
109
108
|
}
|
|
@@ -10,7 +10,7 @@ function* generateClassProperty(styleIndex, classNameWithDot, offset, propertyTy
|
|
|
10
10
|
classNameWithDot.slice(1),
|
|
11
11
|
'style_' + styleIndex,
|
|
12
12
|
offset + 1,
|
|
13
|
-
utils_1.combineLastMapping
|
|
13
|
+
utils_1.combineLastMapping,
|
|
14
14
|
], `'`);
|
|
15
15
|
yield `: ${propertyType}`;
|
|
16
16
|
yield ` }`;
|
|
@@ -6,7 +6,7 @@ const wrapWith_1 = require("../utils/wrapWith");
|
|
|
6
6
|
function* generateStyleImports(style) {
|
|
7
7
|
const features = {
|
|
8
8
|
navigation: true,
|
|
9
|
-
verification: true
|
|
9
|
+
verification: true,
|
|
10
10
|
};
|
|
11
11
|
if (typeof style.src === 'object') {
|
|
12
12
|
yield `${utils_1.newLine} & typeof import(`;
|
|
@@ -19,7 +19,7 @@ function* generateStyleImports(style) {
|
|
|
19
19
|
text,
|
|
20
20
|
style.name,
|
|
21
21
|
offset,
|
|
22
|
-
features
|
|
22
|
+
features,
|
|
23
23
|
];
|
|
24
24
|
yield `').default`;
|
|
25
25
|
}
|
|
@@ -114,7 +114,6 @@ export declare function createTemplateCodegenContext(options: Pick<TemplateCodeg
|
|
|
114
114
|
};
|
|
115
115
|
codeFeatures: {
|
|
116
116
|
all: VueCodeInformation;
|
|
117
|
-
none: VueCodeInformation;
|
|
118
117
|
verification: VueCodeInformation;
|
|
119
118
|
completion: VueCodeInformation;
|
|
120
119
|
additionalCompletion: VueCodeInformation;
|
|
@@ -125,6 +124,7 @@ export declare function createTemplateCodegenContext(options: Pick<TemplateCodeg
|
|
|
125
124
|
navigationAndAdditionalCompletion: VueCodeInformation;
|
|
126
125
|
navigationAndVerification: VueCodeInformation;
|
|
127
126
|
withoutNavigation: VueCodeInformation;
|
|
127
|
+
semanticWithoutHighlight: VueCodeInformation;
|
|
128
128
|
withoutHighlight: VueCodeInformation;
|
|
129
129
|
withoutHighlightAndNavigation: VueCodeInformation;
|
|
130
130
|
withoutHighlightAndCompletion: VueCodeInformation;
|
|
@@ -243,7 +243,7 @@ function createTemplateCodegenContext(options) {
|
|
|
243
243
|
offset,
|
|
244
244
|
{
|
|
245
245
|
...codeFeatures_1.codeFeatures.additionalCompletion,
|
|
246
|
-
...codeFeatures_1.codeFeatures.
|
|
246
|
+
...codeFeatures_1.codeFeatures.semanticWithoutHighlight,
|
|
247
247
|
},
|
|
248
248
|
];
|
|
249
249
|
}
|
|
@@ -55,7 +55,6 @@ function* generateComponent(options, ctx, node) {
|
|
|
55
55
|
dynamicTagInfo = {
|
|
56
56
|
tag: prop.exp.content,
|
|
57
57
|
offsets: [prop.exp.loc.start.offset],
|
|
58
|
-
astHolder: prop.exp.loc,
|
|
59
58
|
};
|
|
60
59
|
props = props.filter(p => p !== prop);
|
|
61
60
|
break;
|
|
@@ -67,7 +66,6 @@ function* generateComponent(options, ctx, node) {
|
|
|
67
66
|
dynamicTagInfo = {
|
|
68
67
|
tag: node.tag,
|
|
69
68
|
offsets: tagOffsets,
|
|
70
|
-
astHolder: node.loc,
|
|
71
69
|
};
|
|
72
70
|
}
|
|
73
71
|
if (matchImportName) {
|
|
@@ -93,10 +91,10 @@ function* generateComponent(options, ctx, node) {
|
|
|
93
91
|
}
|
|
94
92
|
else if (dynamicTagInfo) {
|
|
95
93
|
yield `const ${componentOriginalVar} = (`;
|
|
96
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, dynamicTagInfo.tag, dynamicTagInfo.offsets[0],
|
|
94
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, dynamicTagInfo.tag, dynamicTagInfo.offsets[0], `(`, `)`);
|
|
97
95
|
if (dynamicTagInfo.offsets[1] !== undefined) {
|
|
98
96
|
yield `,`;
|
|
99
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.withoutCompletion, dynamicTagInfo.tag, dynamicTagInfo.offsets[1],
|
|
97
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.withoutCompletion, dynamicTagInfo.tag, dynamicTagInfo.offsets[1], `(`, `)`);
|
|
100
98
|
}
|
|
101
99
|
yield `)${utils_1.endOfLine}`;
|
|
102
100
|
}
|
|
@@ -151,7 +149,7 @@ function* generateComponent(options, ctx, node) {
|
|
|
151
149
|
// https://typescript.tv/errors/#ts6133
|
|
152
150
|
return String(code) !== '6133';
|
|
153
151
|
},
|
|
154
|
-
}
|
|
152
|
+
},
|
|
155
153
|
}), componentVNodeVar);
|
|
156
154
|
yield ` = ${componentFunctionalVar}`;
|
|
157
155
|
yield* generateComponentGeneric(ctx);
|
|
@@ -231,7 +229,7 @@ function* generateElement(options, ctx, node) {
|
|
|
231
229
|
}
|
|
232
230
|
function* generateFailedPropExps(options, ctx, failedPropExps) {
|
|
233
231
|
for (const failedExp of failedPropExps) {
|
|
234
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, failedExp.node.loc.source, failedExp.node.loc.start.offset, failedExp.
|
|
232
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, failedExp.node.loc.source, failedExp.node.loc.start.offset, failedExp.prefix, failedExp.suffix);
|
|
235
233
|
yield utils_1.endOfLine;
|
|
236
234
|
}
|
|
237
235
|
}
|
|
@@ -268,7 +266,7 @@ function* generateComponentGeneric(ctx) {
|
|
|
268
266
|
content,
|
|
269
267
|
'template',
|
|
270
268
|
offset,
|
|
271
|
-
ctx.codeFeatures.all
|
|
269
|
+
ctx.codeFeatures.all,
|
|
272
270
|
], `>`);
|
|
273
271
|
}
|
|
274
272
|
}
|
|
@@ -280,7 +278,7 @@ function* generateElementReference(options, ctx, node) {
|
|
|
280
278
|
const [content, startOffset] = (0, utils_1.normalizeAttributeValue)(prop.value);
|
|
281
279
|
// navigation support for `const foo = ref()`
|
|
282
280
|
yield `/** @type {typeof __VLS_ctx`;
|
|
283
|
-
yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, content, startOffset, ctx.codeFeatures.navigation
|
|
281
|
+
yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, content, startOffset, ctx.codeFeatures.navigation);
|
|
284
282
|
yield `} */${utils_1.endOfLine}`;
|
|
285
283
|
if (utils_1.identifierRegex.test(content) && !options.templateRefNames.has(content)) {
|
|
286
284
|
ctx.accessExternalVariable(content, startOffset);
|
|
@@ -53,7 +53,7 @@ function* generateArg(options, ctx, prop) {
|
|
|
53
53
|
yield* (0, stringLiteralKey_1.generateStringLiteralKey)(arg.content, startOffset, ctx.codeFeatures.all);
|
|
54
54
|
}
|
|
55
55
|
else {
|
|
56
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, arg.content, startOffset,
|
|
56
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, arg.content, startOffset, `(`, `)`);
|
|
57
57
|
}
|
|
58
58
|
yield `, `;
|
|
59
59
|
}
|
|
@@ -45,7 +45,7 @@ function* generateElementEvents(options, ctx, node, componentOriginalVar, compon
|
|
|
45
45
|
const propName = (0, shared_1.camelize)(propPrefix + source);
|
|
46
46
|
const emitName = emitPrefix + source;
|
|
47
47
|
const camelizedEmitName = (0, shared_1.camelize)(emitName);
|
|
48
|
-
yield `(): __VLS_NormalizeComponentEvent<typeof ${propsVar}, typeof ${emitsVar}, '${propName}', '${emitName}', '${camelizedEmitName}'>
|
|
48
|
+
yield `const ${ctx.getInternalVariable()}: __VLS_NormalizeComponentEvent<typeof ${propsVar}, typeof ${emitsVar}, '${propName}', '${emitName}', '${camelizedEmitName}'> = (${utils_1.newLine}`;
|
|
49
49
|
if (prop.name === 'on') {
|
|
50
50
|
yield `{ `;
|
|
51
51
|
yield* generateEventArg(ctx, source, start, emitPrefix.slice(0, -1), ctx.codeFeatures.navigation);
|
|
@@ -86,17 +86,17 @@ function* generateEventExpression(options, ctx, prop) {
|
|
|
86
86
|
let prefix = `(`;
|
|
87
87
|
let suffix = `)`;
|
|
88
88
|
let isFirstMapping = true;
|
|
89
|
-
const ast = (0, utils_1.createTsAst)(options.ts,
|
|
90
|
-
const
|
|
91
|
-
if (
|
|
92
|
-
yield `(...[$event]) => {${utils_1.newLine}`;
|
|
89
|
+
const ast = (0, utils_1.createTsAst)(options.ts, options.template.ast, prop.exp.content);
|
|
90
|
+
const isCompound = isCompoundExpression(options.ts, ast);
|
|
91
|
+
if (isCompound) {
|
|
93
92
|
ctx.addLocalVariable('$event');
|
|
93
|
+
yield `(...[$event]) => {${utils_1.newLine}`;
|
|
94
94
|
yield* ctx.generateConditionGuards();
|
|
95
95
|
prefix = ``;
|
|
96
96
|
suffix = ``;
|
|
97
97
|
}
|
|
98
98
|
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', offset => {
|
|
99
|
-
if (
|
|
99
|
+
if (isCompound && isFirstMapping) {
|
|
100
100
|
isFirstMapping = false;
|
|
101
101
|
ctx.inlayHints.push({
|
|
102
102
|
blockName: 'template',
|
|
@@ -112,10 +112,11 @@ function* generateEventExpression(options, ctx, prop) {
|
|
|
112
112
|
});
|
|
113
113
|
}
|
|
114
114
|
return ctx.codeFeatures.all;
|
|
115
|
-
}, prop.exp.content, prop.exp.loc.start.offset,
|
|
116
|
-
if (
|
|
115
|
+
}, prop.exp.content, prop.exp.loc.start.offset, prefix, suffix);
|
|
116
|
+
if (isCompound) {
|
|
117
117
|
ctx.removeLocalVariable('$event');
|
|
118
118
|
yield utils_1.endOfLine;
|
|
119
|
+
yield* ctx.generateAutoImportCompletion();
|
|
119
120
|
yield `}`;
|
|
120
121
|
}
|
|
121
122
|
}
|
|
@@ -127,7 +128,7 @@ function* generateModelEventExpression(options, ctx, prop) {
|
|
|
127
128
|
if (prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
128
129
|
yield `(...[$event]) => {${utils_1.newLine}`;
|
|
129
130
|
yield* ctx.generateConditionGuards();
|
|
130
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.verification, prop.exp.content, prop.exp.loc.start.offset
|
|
131
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.verification, prop.exp.content, prop.exp.loc.start.offset);
|
|
131
132
|
yield ` = $event${utils_1.endOfLine}`;
|
|
132
133
|
yield `}`;
|
|
133
134
|
}
|
|
@@ -82,7 +82,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
|
|
|
82
82
|
yield `...{ `;
|
|
83
83
|
}
|
|
84
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,
|
|
85
|
+
? (0, objectProperty_1.generateObjectProperty)(options, ctx, propName, prop.arg.loc.start.offset, codeInfo, shouldCamelize)
|
|
86
86
|
: (0, wrapWith_1.wrapWith)(prop.loc.start.offset, prop.loc.start.offset + 'v-model'.length, ctx.codeFeatures.withoutHighlightAndCompletion, propName)), `: `, ...(0, wrapWith_1.wrapWith)(prop.arg?.loc.start.offset ?? prop.loc.start.offset, prop.arg?.loc.end.offset ?? prop.loc.end.offset, ctx.codeFeatures.verification, ...generatePropExp(options, ctx, prop, prop.exp, enableCodeFeatures)))];
|
|
87
87
|
if (enableCodeFeatures) {
|
|
88
88
|
yield* codes;
|
|
@@ -97,7 +97,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
|
|
|
97
97
|
if (isComponent && prop.name === 'model' && prop.modifiers.length) {
|
|
98
98
|
const propertyName = prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
99
99
|
? !prop.arg.isStatic
|
|
100
|
-
? `[__VLS_tryAsConstant(
|
|
100
|
+
? `[__VLS_tryAsConstant(\`\${${prop.arg.content}}Modifiers\`)]`
|
|
101
101
|
: (0, shared_1.camelize)(propName) + `Modifiers`
|
|
102
102
|
: `modelModifiers`;
|
|
103
103
|
const codes = [...(0, elementDirectives_1.generateModifiers)(options, ctx, prop, propertyName)];
|
|
@@ -120,7 +120,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
|
|
|
120
120
|
if (shouldSpread) {
|
|
121
121
|
yield `...{ `;
|
|
122
122
|
}
|
|
123
|
-
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,
|
|
123
|
+
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, shouldCamelize), `: `, ...(prop.value
|
|
124
124
|
? generateAttrValue(prop.value, ctx.codeFeatures.withoutNavigation)
|
|
125
125
|
: [`true`]))];
|
|
126
126
|
if (enableCodeFeatures) {
|
|
@@ -163,7 +163,7 @@ function* generatePropExp(options, ctx, prop, exp, enableCodeFeatures = true) {
|
|
|
163
163
|
: ctx.codeFeatures.all;
|
|
164
164
|
if (exp && exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY) { // style='z-index: 2' will compile to {'z-index':'2'}
|
|
165
165
|
if (!isShorthand) { // vue 3.4+
|
|
166
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', features, exp.loc.source, exp.loc.start.offset,
|
|
166
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', features, exp.loc.source, exp.loc.start.offset, `(`, `)`);
|
|
167
167
|
}
|
|
168
168
|
else {
|
|
169
169
|
const propVariableName = (0, shared_1.camelize)(exp.loc.source);
|
|
@@ -38,7 +38,7 @@ function* generateTemplate(options) {
|
|
|
38
38
|
['$slots', yield* generateSlots(options, ctx)],
|
|
39
39
|
['$attrs', yield* generateInheritedAttrs(options, ctx)],
|
|
40
40
|
['$refs', yield* generateTemplateRefs(options, ctx)],
|
|
41
|
-
['$el', yield* generateRootEl(ctx)]
|
|
41
|
+
['$el', yield* generateRootEl(ctx)],
|
|
42
42
|
];
|
|
43
43
|
yield `var __VLS_dollars!: {${utils_1.newLine}`;
|
|
44
44
|
for (const [name, type] of speicalTypes) {
|
|
@@ -56,7 +56,7 @@ function* generateSlots(options, ctx) {
|
|
|
56
56
|
for (const slot of ctx.slots) {
|
|
57
57
|
yield `${utils_1.newLine}& { `;
|
|
58
58
|
if (slot.name && slot.offset !== undefined) {
|
|
59
|
-
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slot.name, slot.offset, ctx.codeFeatures.withoutHighlightAndCompletion
|
|
59
|
+
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slot.name, slot.offset, ctx.codeFeatures.withoutHighlightAndCompletion);
|
|
60
60
|
}
|
|
61
61
|
else {
|
|
62
62
|
yield* (0, wrapWith_1.wrapWith)(slot.tagRange[0], slot.tagRange[1], ctx.codeFeatures.withoutHighlightAndCompletion, `default`);
|
|
@@ -81,7 +81,7 @@ function* generateInheritedAttrs(options, ctx) {
|
|
|
81
81
|
loc.source,
|
|
82
82
|
'template',
|
|
83
83
|
loc.start.offset,
|
|
84
|
-
ctx.codeFeatures.all
|
|
84
|
+
ctx.codeFeatures.all,
|
|
85
85
|
];
|
|
86
86
|
yield `,`;
|
|
87
87
|
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import type * as ts from 'typescript';
|
|
2
1
|
import type { Code, VueCodeInformation } from '../../types';
|
|
2
|
+
import type { ScriptCodegenOptions } from '../script';
|
|
3
3
|
import type { TemplateCodegenContext } from './context';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
destructuredPropNames: Set<string> | undefined;
|
|
7
|
-
templateRefNames: Set<string> | undefined;
|
|
8
|
-
}, ctx: TemplateCodegenContext, source: string, data: VueCodeInformation | ((offset: number) => VueCodeInformation) | undefined, code: string, start: number | undefined, astHolder?: any, prefix?: string, suffix?: string): Generator<Code>;
|
|
4
|
+
import type { TemplateCodegenOptions } from './index';
|
|
5
|
+
export declare function generateInterpolation(options: TemplateCodegenOptions | ScriptCodegenOptions, ctx: TemplateCodegenContext, source: string, data: VueCodeInformation | ((offset: number) => VueCodeInformation) | undefined, code: string, start: number | undefined, prefix?: string, suffix?: string): Generator<Code>;
|
|
@@ -6,8 +6,10 @@ const shared_2 = require("../../utils/shared");
|
|
|
6
6
|
const utils_1 = require("../utils");
|
|
7
7
|
// https://github.com/vuejs/core/blob/fb0c3ca519f1fccf52049cd6b8db3a67a669afe9/packages/compiler-core/src/transforms/transformExpression.ts#L47
|
|
8
8
|
const isLiteralWhitelisted = /*@__PURE__*/ (0, shared_1.makeMap)('true,false,null,this');
|
|
9
|
-
function* generateInterpolation(options, ctx, source, data, code, start,
|
|
10
|
-
|
|
9
|
+
function* generateInterpolation(options, ctx, source, data, code, start, prefix = '', suffix = '') {
|
|
10
|
+
const { ts, destructuredPropNames, templateRefNames, } = options;
|
|
11
|
+
const template = 'template' in options ? options.template : options.sfc.template;
|
|
12
|
+
for (let [section, offset, type] of forEachInterpolationSegment(ts, template, destructuredPropNames, templateRefNames, ctx, code, start, prefix, suffix)) {
|
|
11
13
|
if (offset === undefined) {
|
|
12
14
|
yield section;
|
|
13
15
|
}
|
|
@@ -46,7 +48,7 @@ function* generateInterpolation(options, ctx, source, data, code, start, astHold
|
|
|
46
48
|
}
|
|
47
49
|
}
|
|
48
50
|
;
|
|
49
|
-
function* forEachInterpolationSegment(ts, destructuredPropNames, templateRefNames, ctx, originalCode, start,
|
|
51
|
+
function* forEachInterpolationSegment(ts, template, destructuredPropNames, templateRefNames, ctx, originalCode, start, prefix, suffix) {
|
|
50
52
|
const code = prefix + originalCode + suffix;
|
|
51
53
|
const offset = start !== undefined ? start - prefix.length : undefined;
|
|
52
54
|
let ctxVars = [];
|
|
@@ -57,7 +59,7 @@ function* forEachInterpolationSegment(ts, destructuredPropNames, templateRefName
|
|
|
57
59
|
});
|
|
58
60
|
}
|
|
59
61
|
else {
|
|
60
|
-
const ast = (0, utils_1.createTsAst)(ts,
|
|
62
|
+
const ast = (0, utils_1.createTsAst)(ts, template?.ast, code);
|
|
61
63
|
const varCb = (id, isShorthand) => {
|
|
62
64
|
const text = (0, shared_2.getNodeText)(ts, id, ast);
|
|
63
65
|
if (!shouldIdentifierSkipped(ctx, text, destructuredPropNames)) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Code, VueCodeInformation } from '../../types';
|
|
2
2
|
import type { TemplateCodegenContext } from './context';
|
|
3
3
|
import type { TemplateCodegenOptions } from './index';
|
|
4
|
-
export declare function generateObjectProperty(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, code: string, offset: number, features: VueCodeInformation,
|
|
4
|
+
export declare function generateObjectProperty(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, code: string, offset: number, features: VueCodeInformation, shouldCamelize?: boolean, shouldBeConstant?: boolean): Generator<Code>;
|
|
@@ -7,13 +7,13 @@ const camelized_1 = require("../utils/camelized");
|
|
|
7
7
|
const stringLiteralKey_1 = require("../utils/stringLiteralKey");
|
|
8
8
|
const wrapWith_1 = require("../utils/wrapWith");
|
|
9
9
|
const interpolation_1 = require("./interpolation");
|
|
10
|
-
function* generateObjectProperty(options, ctx, code, offset, features,
|
|
11
|
-
if (code.startsWith('[') && code.endsWith(']')
|
|
10
|
+
function* generateObjectProperty(options, ctx, code, offset, features, shouldCamelize = false, shouldBeConstant = false) {
|
|
11
|
+
if (code.startsWith('[') && code.endsWith(']')) {
|
|
12
12
|
if (shouldBeConstant) {
|
|
13
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', features, code.slice(1, -1), offset + 1,
|
|
13
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', features, code.slice(1, -1), offset + 1, `[__VLS_tryAsConstant(`, `)]`);
|
|
14
14
|
}
|
|
15
15
|
else {
|
|
16
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', features, code, offset
|
|
16
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', features, code, offset);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
else if (shouldCamelize) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Code, VueCodeInformation } from '../../types';
|
|
2
2
|
import type { TemplateCodegenContext } from './context';
|
|
3
3
|
import type { TemplateCodegenOptions } from './index';
|
|
4
|
-
export declare function generatePropertyAccess(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, code: string, offset?: number, features?: VueCodeInformation
|
|
4
|
+
export declare function generatePropertyAccess(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, code: string, offset?: number, features?: VueCodeInformation): Generator<Code>;
|
|
@@ -4,7 +4,7 @@ exports.generatePropertyAccess = generatePropertyAccess;
|
|
|
4
4
|
const utils_1 = require("../utils");
|
|
5
5
|
const stringLiteralKey_1 = require("../utils/stringLiteralKey");
|
|
6
6
|
const interpolation_1 = require("./interpolation");
|
|
7
|
-
function* generatePropertyAccess(options, ctx, code, offset, features
|
|
7
|
+
function* generatePropertyAccess(options, ctx, code, offset, features) {
|
|
8
8
|
if (!options.compilerOptions.noPropertyAccessFromIndexSignature && utils_1.identifierRegex.test(code)) {
|
|
9
9
|
yield `.`;
|
|
10
10
|
yield offset !== undefined && features
|
|
@@ -12,7 +12,7 @@ function* generatePropertyAccess(options, ctx, code, offset, features, astHolder
|
|
|
12
12
|
: code;
|
|
13
13
|
}
|
|
14
14
|
else if (code.startsWith('[') && code.endsWith(']')) {
|
|
15
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', features, code, offset
|
|
15
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', features, code, offset);
|
|
16
16
|
}
|
|
17
17
|
else {
|
|
18
18
|
yield `[`;
|
|
@@ -40,7 +40,7 @@ function* generateSlotOutlet(options, ctx, node) {
|
|
|
40
40
|
codes = [
|
|
41
41
|
`[`,
|
|
42
42
|
...(0, elementProps_1.generatePropExp)(options, ctx, nameProp, nameProp.exp),
|
|
43
|
-
`]
|
|
43
|
+
`]`,
|
|
44
44
|
];
|
|
45
45
|
}
|
|
46
46
|
else {
|
|
@@ -77,7 +77,7 @@ function* generateSlotOutlet(options, ctx, node) {
|
|
|
77
77
|
}
|
|
78
78
|
const expVar = ctx.getInternalVariable();
|
|
79
79
|
yield `var ${expVar} = __VLS_tryAsConstant(`;
|
|
80
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, nameProp.exp.content, nameProp.exp.loc.start.offset
|
|
80
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, nameProp.exp.content, nameProp.exp.loc.start.offset);
|
|
81
81
|
yield `)${utils_1.endOfLine}`;
|
|
82
82
|
ctx.dynamicSlots.push({
|
|
83
83
|
expVar: ctx.getHoistVariable(expVar),
|
|
@@ -130,7 +130,7 @@ function collectStyleScopedClassReferences(options, ctx, node) {
|
|
|
130
130
|
ctx.scopedClasses.push({
|
|
131
131
|
source: 'template',
|
|
132
132
|
className: text,
|
|
133
|
-
offset: node.end - text.length + startOffset
|
|
133
|
+
offset: node.end - text.length + startOffset,
|
|
134
134
|
});
|
|
135
135
|
}
|
|
136
136
|
}
|
|
@@ -146,7 +146,7 @@ function collectClasses(content, startOffset = 0) {
|
|
|
146
146
|
classes.push({
|
|
147
147
|
source: 'template',
|
|
148
148
|
className: currentClassName,
|
|
149
|
-
offset: offset + startOffset
|
|
149
|
+
offset: offset + startOffset,
|
|
150
150
|
});
|
|
151
151
|
offset += currentClassName.length;
|
|
152
152
|
currentClassName = '';
|
|
@@ -83,7 +83,7 @@ function* generateTemplateChild(options, ctx, node, enterNode = true) {
|
|
|
83
83
|
else if (node.type === CompilerDOM.NodeTypes.INTERPOLATION) {
|
|
84
84
|
// {{ ... }}
|
|
85
85
|
const [content, start] = parseInterpolationNode(node, options.template.content);
|
|
86
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, content, start,
|
|
86
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, content, start, `(`, `)${utils_1.endOfLine}`);
|
|
87
87
|
}
|
|
88
88
|
else if (node.type === CompilerDOM.NodeTypes.IF) {
|
|
89
89
|
// v-if / v-else-if / v-else
|
|
@@ -12,7 +12,7 @@ function* generateVFor(options, ctx, node) {
|
|
|
12
12
|
const forBlockVars = [];
|
|
13
13
|
yield `for (const [`;
|
|
14
14
|
if (leftExpressionRange && leftExpressionText) {
|
|
15
|
-
const collectAst = (0, utils_1.createTsAst)(options.ts,
|
|
15
|
+
const collectAst = (0, utils_1.createTsAst)(options.ts, options.template.ast, `const [${leftExpressionText}]`);
|
|
16
16
|
(0, utils_1.collectVars)(options.ts, collectAst, collectAst, forBlockVars);
|
|
17
17
|
yield [
|
|
18
18
|
leftExpressionText,
|
|
@@ -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,
|
|
27
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, source.content, source.loc.start.offset, `(`, `)`);
|
|
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,
|
|
49
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, prop.value.content, prop.value.loc.start.offset, `(`, `)`);
|
|
50
50
|
yield utils_1.endOfLine;
|
|
51
51
|
}
|
|
52
52
|
}
|
|
@@ -21,7 +21,7 @@ function* generateVIf(options, ctx, node) {
|
|
|
21
21
|
}
|
|
22
22
|
let addedBlockCondition = false;
|
|
23
23
|
if (branch.condition?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
24
|
-
const codes = [...(0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, branch.condition.content, branch.condition.loc.start.offset,
|
|
24
|
+
const codes = [...(0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, branch.condition.content, branch.condition.loc.start.offset, `(`, `)`)];
|
|
25
25
|
yield* codes;
|
|
26
26
|
ctx.blockConditions.push((0, muggle_string_1.toString)(codes));
|
|
27
27
|
addedBlockCondition = true;
|
|
@@ -21,7 +21,7 @@ function* generateVSlot(options, ctx, node, slotDir) {
|
|
|
21
21
|
yield `const { `;
|
|
22
22
|
if (slotDir) {
|
|
23
23
|
if (slotDir.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && slotDir.arg.content) {
|
|
24
|
-
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slotDir.arg.loc.source, slotDir.arg.loc.start.offset, slotDir.arg.isStatic ? ctx.codeFeatures.withoutHighlight : ctx.codeFeatures.all,
|
|
24
|
+
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slotDir.arg.loc.source, slotDir.arg.loc.start.offset, slotDir.arg.isStatic ? ctx.codeFeatures.withoutHighlight : ctx.codeFeatures.all, false, true);
|
|
25
25
|
}
|
|
26
26
|
else {
|
|
27
27
|
yield* (0, wrapWith_1.wrapWith)(slotDir.loc.start.offset, slotDir.loc.start.offset + (slotDir.rawName?.length ?? 0), ctx.codeFeatures.withoutHighlightAndCompletion, `default`);
|
|
@@ -35,7 +35,7 @@ function* generateVSlot(options, ctx, node, slotDir) {
|
|
|
35
35
|
yield `: ${slotVar} } = ${ctx.currentComponent.ctxVar}.slots!${utils_1.endOfLine}`;
|
|
36
36
|
}
|
|
37
37
|
if (slotDir?.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
38
|
-
const slotAst = (0, utils_1.createTsAst)(options.ts,
|
|
38
|
+
const slotAst = (0, utils_1.createTsAst)(options.ts, options.template.ast, `(${slotDir.exp.content}) => {}`);
|
|
39
39
|
(0, utils_1.collectVars)(options.ts, slotAst, slotAst, slotBlockVars);
|
|
40
40
|
yield* generateSlotParameters(options, ctx, slotAst, slotDir.exp, slotVar);
|
|
41
41
|
}
|
|
@@ -16,5 +16,5 @@ export declare function collectIdentifiers(ts: typeof import('typescript'), node
|
|
|
16
16
|
initializer: ts.Expression | undefined;
|
|
17
17
|
}[];
|
|
18
18
|
export declare function normalizeAttributeValue(node: CompilerDOM.TextNode): [string, number];
|
|
19
|
-
export declare function createTsAst(ts: typeof import('typescript'),
|
|
19
|
+
export declare function createTsAst(ts: typeof import('typescript'), templateAst: CompilerDOM.RootNode | undefined, text: string): ts.SourceFile;
|
|
20
20
|
export declare function generateSfcBlockSection(block: SfcBlock, start: number, end: number, features: VueCodeInformation): Code;
|
|
@@ -49,12 +49,15 @@ function normalizeAttributeValue(node) {
|
|
|
49
49
|
}
|
|
50
50
|
return [content, offset];
|
|
51
51
|
}
|
|
52
|
-
function createTsAst(ts,
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
function createTsAst(ts, templateAst, text) {
|
|
53
|
+
const inlineTsAsts = templateAst?.__volar_inlineTsAsts;
|
|
54
|
+
let ast = inlineTsAsts?.get(text);
|
|
55
|
+
if (!ast) {
|
|
56
|
+
ast = ts.createSourceFile('/a.ts', text, 99);
|
|
57
|
+
inlineTsAsts?.set(text, ast);
|
|
56
58
|
}
|
|
57
|
-
|
|
59
|
+
ast.__volar_used = true;
|
|
60
|
+
return ast;
|
|
58
61
|
}
|
|
59
62
|
function generateSfcBlockSection(block, start, end, features) {
|
|
60
63
|
return [
|
|
@@ -143,7 +143,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
143
143
|
defineProps = {
|
|
144
144
|
...parseCallExpressionAssignment(node, parent),
|
|
145
145
|
statement: getStatementRange(ts, parents, node, ast),
|
|
146
|
-
argNode: node.arguments[0]
|
|
146
|
+
argNode: node.arguments[0],
|
|
147
147
|
};
|
|
148
148
|
if (ts.isVariableDeclaration(parent) && ts.isObjectBindingPattern(parent.name)) {
|
|
149
149
|
defineProps.destructured = new Map();
|
|
@@ -172,13 +172,13 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
172
172
|
callExp: _getStartEnd(node),
|
|
173
173
|
exp: _getStartEnd(node.expression),
|
|
174
174
|
arg: arg ? _getStartEnd(arg) : undefined,
|
|
175
|
-
argNode: arg
|
|
175
|
+
argNode: arg,
|
|
176
176
|
};
|
|
177
177
|
}
|
|
178
178
|
else if (vueCompilerOptions.macros.defineEmits.includes(callText)) {
|
|
179
179
|
defineEmits = {
|
|
180
180
|
...parseCallExpressionAssignment(node, parent),
|
|
181
|
-
statement: getStatementRange(ts, parents, node, ast)
|
|
181
|
+
statement: getStatementRange(ts, parents, node, ast),
|
|
182
182
|
};
|
|
183
183
|
if (node.typeArguments?.length && ts.isTypeLiteralNode(node.typeArguments[0])) {
|
|
184
184
|
for (const member of node.typeArguments[0].members) {
|
|
@@ -195,7 +195,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
195
195
|
else if (vueCompilerOptions.macros.defineSlots.includes(callText)) {
|
|
196
196
|
defineSlots = {
|
|
197
197
|
...parseCallExpressionAssignment(node, parent),
|
|
198
|
-
statement: getStatementRange(ts, parents, node, ast)
|
|
198
|
+
statement: getStatementRange(ts, parents, node, ast),
|
|
199
199
|
};
|
|
200
200
|
}
|
|
201
201
|
else if (vueCompilerOptions.macros.defineExpose.includes(callText)) {
|
|
@@ -274,20 +274,20 @@ function parseBindingRanges(ts, ast) {
|
|
|
274
274
|
else if (ts.isFunctionDeclaration(node)) {
|
|
275
275
|
if (node.name && ts.isIdentifier(node.name)) {
|
|
276
276
|
bindings.push({
|
|
277
|
-
range: _getStartEnd(node.name)
|
|
277
|
+
range: _getStartEnd(node.name),
|
|
278
278
|
});
|
|
279
279
|
}
|
|
280
280
|
}
|
|
281
281
|
else if (ts.isClassDeclaration(node)) {
|
|
282
282
|
if (node.name) {
|
|
283
283
|
bindings.push({
|
|
284
|
-
range: _getStartEnd(node.name)
|
|
284
|
+
range: _getStartEnd(node.name),
|
|
285
285
|
});
|
|
286
286
|
}
|
|
287
287
|
}
|
|
288
288
|
else if (ts.isEnumDeclaration(node)) {
|
|
289
289
|
bindings.push({
|
|
290
|
-
range: _getStartEnd(node.name)
|
|
290
|
+
range: _getStartEnd(node.name),
|
|
291
291
|
});
|
|
292
292
|
}
|
|
293
293
|
if (ts.isImportDeclaration(node)) {
|
|
@@ -298,7 +298,7 @@ function parseBindingRanges(ts, ast) {
|
|
|
298
298
|
bindings.push({
|
|
299
299
|
range: _getStartEnd(name),
|
|
300
300
|
moduleName,
|
|
301
|
-
isDefaultImport: true
|
|
301
|
+
isDefaultImport: true,
|
|
302
302
|
});
|
|
303
303
|
}
|
|
304
304
|
if (namedBindings) {
|
|
@@ -310,7 +310,7 @@ function parseBindingRanges(ts, ast) {
|
|
|
310
310
|
bindings.push({
|
|
311
311
|
range: _getStartEnd(element.name),
|
|
312
312
|
moduleName,
|
|
313
|
-
isDefaultImport: element.propertyName?.text === 'default'
|
|
313
|
+
isDefaultImport: element.propertyName?.text === 'default',
|
|
314
314
|
});
|
|
315
315
|
}
|
|
316
316
|
}
|
|
@@ -318,7 +318,7 @@ function parseBindingRanges(ts, ast) {
|
|
|
318
318
|
bindings.push({
|
|
319
319
|
range: _getStartEnd(namedBindings.name),
|
|
320
320
|
moduleName,
|
|
321
|
-
isNamespace: true
|
|
321
|
+
isNamespace: true,
|
|
322
322
|
});
|
|
323
323
|
}
|
|
324
324
|
}
|
package/lib/plugins/file-html.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const sfcBlockReg =
|
|
4
|
-
const langReg = /\blang\s*=\s*(['
|
|
3
|
+
const sfcBlockReg = /<(script|style)\b([\s\S]*?)>([\s\S]*?)<\/\1>/g;
|
|
4
|
+
const langReg = /\blang\s*=\s*(['"]?)(\S*)\b\1/;
|
|
5
5
|
const plugin = ({ vueCompilerOptions }) => {
|
|
6
6
|
return {
|
|
7
7
|
version: 2.1,
|
|
@@ -83,7 +83,7 @@ const plugin = ({ vueCompilerOptions }) => {
|
|
|
83
83
|
ast: {},
|
|
84
84
|
};
|
|
85
85
|
return sfc;
|
|
86
|
-
}
|
|
86
|
+
},
|
|
87
87
|
};
|
|
88
88
|
};
|
|
89
89
|
exports.default = plugin;
|
package/lib/plugins/file-md.js
CHANGED
|
@@ -8,9 +8,9 @@ const frontmatterReg = /^---[\s\S]*?\n---(?:\r?\n|$)/;
|
|
|
8
8
|
const codeblockReg = /(`{3,})[\s\S]+?\1/g;
|
|
9
9
|
const inlineCodeblockReg = /`[^\n`]+?`/g;
|
|
10
10
|
const latexBlockReg = /(\${2,})[\s\S]+?\1/g;
|
|
11
|
-
const scriptSetupReg =
|
|
12
|
-
const sfcBlockReg =
|
|
13
|
-
const angleBracketReg =
|
|
11
|
+
const scriptSetupReg = /\\<[\s\S]+?>\n?/g;
|
|
12
|
+
const sfcBlockReg = /<(script|style)\b[\s\S]*?>([\s\S]*?)<\/\1>/g;
|
|
13
|
+
const angleBracketReg = /<\S*:\S*>/g;
|
|
14
14
|
const linkReg = /\[[\s\S]*?\]\([\s\S]*?\)/g;
|
|
15
15
|
const codeSnippetImportReg = /^\s*<<<\s*.+/gm;
|
|
16
16
|
const plugin = ({ vueCompilerOptions }) => {
|
|
@@ -92,7 +92,7 @@ const plugin = ({ vueCompilerOptions }) => {
|
|
|
92
92
|
break;
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
|
-
}
|
|
95
|
+
},
|
|
96
96
|
};
|
|
97
97
|
};
|
|
98
98
|
exports.default = plugin;
|
|
@@ -85,7 +85,7 @@ const plugin = ctx => {
|
|
|
85
85
|
&& prop.exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY // style='z-index: 2' will compile to {'z-index':'2'}
|
|
86
86
|
) {
|
|
87
87
|
if (prop.name === 'on' && prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
88
|
-
const ast = (0, utils_1.createTsAst)(ctx.modules.typescript,
|
|
88
|
+
const ast = (0, utils_1.createTsAst)(ctx.modules.typescript, sfc.template.ast, prop.exp.content);
|
|
89
89
|
if ((0, elementEvents_1.isCompoundExpression)(ctx.modules.typescript, ast)) {
|
|
90
90
|
addFormatCodes(prop.exp.loc.source, prop.exp.loc.start.offset, formatBrackets.event);
|
|
91
91
|
}
|
|
@@ -179,7 +179,7 @@ const plugin = ctx => {
|
|
|
179
179
|
else {
|
|
180
180
|
addFormatCodes(content, start, [
|
|
181
181
|
firstLineEmpty ? '(' : '(0 +',
|
|
182
|
-
lastLineEmpty ? ');' : '+ 0);'
|
|
182
|
+
lastLineEmpty ? ');' : '+ 0);',
|
|
183
183
|
]);
|
|
184
184
|
}
|
|
185
185
|
}
|
package/lib/plugins/vue-tsx.d.ts
CHANGED
|
@@ -149,7 +149,6 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
149
149
|
};
|
|
150
150
|
codeFeatures: {
|
|
151
151
|
all: import("../types").VueCodeInformation;
|
|
152
|
-
none: import("../types").VueCodeInformation;
|
|
153
152
|
verification: import("../types").VueCodeInformation;
|
|
154
153
|
completion: import("../types").VueCodeInformation;
|
|
155
154
|
additionalCompletion: import("../types").VueCodeInformation;
|
|
@@ -160,6 +159,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
160
159
|
navigationAndAdditionalCompletion: import("../types").VueCodeInformation;
|
|
161
160
|
navigationAndVerification: import("../types").VueCodeInformation;
|
|
162
161
|
withoutNavigation: import("../types").VueCodeInformation;
|
|
162
|
+
semanticWithoutHighlight: import("../types").VueCodeInformation;
|
|
163
163
|
withoutHighlight: import("../types").VueCodeInformation;
|
|
164
164
|
withoutHighlightAndNavigation: import("../types").VueCodeInformation;
|
|
165
165
|
withoutHighlightAndCompletion: import("../types").VueCodeInformation;
|
package/lib/utils/parseSfc.js
CHANGED
|
@@ -81,7 +81,7 @@ function createBlock(node, source) {
|
|
|
81
81
|
start = {
|
|
82
82
|
line: start.line,
|
|
83
83
|
column: start.column + offset,
|
|
84
|
-
offset: start.offset + offset
|
|
84
|
+
offset: start.offset + offset,
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
87
|
end = Object.assign({}, start);
|
|
@@ -89,14 +89,14 @@ function createBlock(node, source) {
|
|
|
89
89
|
const loc = {
|
|
90
90
|
source: content,
|
|
91
91
|
start,
|
|
92
|
-
end
|
|
92
|
+
end,
|
|
93
93
|
};
|
|
94
94
|
const attrs = {};
|
|
95
95
|
const block = {
|
|
96
96
|
type,
|
|
97
97
|
content,
|
|
98
98
|
loc,
|
|
99
|
-
attrs
|
|
99
|
+
attrs,
|
|
100
100
|
};
|
|
101
101
|
node.props.forEach(p => {
|
|
102
102
|
if (p.type === CompilerDOM.NodeTypes.ATTRIBUTE) {
|
package/lib/utils/ts.js
CHANGED
|
@@ -21,7 +21,7 @@ function createParsedCommandLineByJson(ts, parseConfigHost, rootDir, json, confi
|
|
|
21
21
|
const rawOptions = obj?.vueCompilerOptions ?? {};
|
|
22
22
|
resolver.addConfig(rawOptions, path_browserify_1.posix.dirname(configFile.fileName));
|
|
23
23
|
}
|
|
24
|
-
catch
|
|
24
|
+
catch { }
|
|
25
25
|
}
|
|
26
26
|
const resolvedVueOptions = resolver.build();
|
|
27
27
|
if (skipGlobalTypesSetup) {
|
|
@@ -58,7 +58,7 @@ function createParsedCommandLine(ts, parseConfigHost, tsConfigPath, skipGlobalTy
|
|
|
58
58
|
const rawOptions = obj?.vueCompilerOptions ?? {};
|
|
59
59
|
resolver.addConfig(rawOptions, path_browserify_1.posix.dirname(configFile.fileName));
|
|
60
60
|
}
|
|
61
|
-
catch
|
|
61
|
+
catch { }
|
|
62
62
|
}
|
|
63
63
|
const resolvedVueOptions = resolver.build();
|
|
64
64
|
if (skipGlobalTypesSetup) {
|
|
@@ -82,7 +82,7 @@ function createParsedCommandLine(ts, parseConfigHost, tsConfigPath, skipGlobalTy
|
|
|
82
82
|
vueOptions: resolvedVueOptions,
|
|
83
83
|
};
|
|
84
84
|
}
|
|
85
|
-
catch
|
|
85
|
+
catch {
|
|
86
86
|
// console.warn('Failed to resolve tsconfig path:', tsConfigPath, err);
|
|
87
87
|
return {
|
|
88
88
|
fileNames: [],
|
|
@@ -105,7 +105,7 @@ function proxyParseConfigHostForExtendConfigPaths(parseConfigHost) {
|
|
|
105
105
|
};
|
|
106
106
|
}
|
|
107
107
|
return target[key];
|
|
108
|
-
}
|
|
108
|
+
},
|
|
109
109
|
});
|
|
110
110
|
return {
|
|
111
111
|
host,
|
|
@@ -176,7 +176,7 @@ class CompilerOptionsResolver {
|
|
|
176
176
|
},
|
|
177
177
|
fallthroughComponentNames: [
|
|
178
178
|
...defaults.fallthroughComponentNames,
|
|
179
|
-
...this.options.fallthroughComponentNames ?? []
|
|
179
|
+
...this.options.fallthroughComponentNames ?? [],
|
|
180
180
|
].map(shared_2.hyphenateTag),
|
|
181
181
|
// https://github.com/vuejs/vue-next/blob/master/packages/compiler-dom/src/transforms/vModel.ts#L49-L51
|
|
182
182
|
// https://vuejs.org/guide/essentials/forms.html#form-input-bindings
|
|
@@ -205,7 +205,7 @@ function resolvePath(scriptPath, root) {
|
|
|
205
205
|
// console.warn('failed to resolve path:', scriptPath, 'require.resolve is not supported in web');
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
|
-
catch
|
|
208
|
+
catch {
|
|
209
209
|
// console.warn(error);
|
|
210
210
|
}
|
|
211
211
|
}
|
|
@@ -261,13 +261,13 @@ function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTemplates = f
|
|
|
261
261
|
plugins: [],
|
|
262
262
|
experimentalModelPropName: {
|
|
263
263
|
'': {
|
|
264
|
-
input: true
|
|
264
|
+
input: true,
|
|
265
265
|
},
|
|
266
266
|
value: {
|
|
267
267
|
input: { type: 'text' },
|
|
268
268
|
textarea: true,
|
|
269
|
-
select: true
|
|
270
|
-
}
|
|
269
|
+
select: true,
|
|
270
|
+
},
|
|
271
271
|
},
|
|
272
272
|
};
|
|
273
273
|
}
|
|
@@ -120,12 +120,29 @@ function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
|
|
|
120
120
|
};
|
|
121
121
|
function computedTemplateAst(base) {
|
|
122
122
|
let cache;
|
|
123
|
+
let inlineTsAsts;
|
|
124
|
+
function updateInlineTsAsts(newAst, oldAst) {
|
|
125
|
+
const newTsAsts = newAst.__volar_inlineTsAsts ??= new Map();
|
|
126
|
+
const oldTsAsts = oldAst?.__volar_inlineTsAsts ?? inlineTsAsts;
|
|
127
|
+
if (oldTsAsts) {
|
|
128
|
+
for (const [text, ast] of oldTsAsts) {
|
|
129
|
+
if (!ast.__volar_used) {
|
|
130
|
+
oldTsAsts.delete(text);
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
newTsAsts.set(text, ast);
|
|
134
|
+
ast.__volar_used = false;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
inlineTsAsts = new Map(newTsAsts);
|
|
139
|
+
}
|
|
123
140
|
return (0, alien_signals_1.computed)(() => {
|
|
124
141
|
if (cache?.template === base.content) {
|
|
125
142
|
return {
|
|
126
143
|
errors: [],
|
|
127
144
|
warnings: [],
|
|
128
|
-
ast: cache
|
|
145
|
+
ast: cache.result.ast,
|
|
129
146
|
};
|
|
130
147
|
}
|
|
131
148
|
// incremental update
|
|
@@ -142,6 +159,7 @@ function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
|
|
|
142
159
|
newText,
|
|
143
160
|
});
|
|
144
161
|
if (newResult) {
|
|
162
|
+
updateInlineTsAsts(newResult.ast, cache.result.ast);
|
|
145
163
|
cache.template = base.content;
|
|
146
164
|
cache.snapshot = getUntrackedSnapshot();
|
|
147
165
|
cache.result = newResult;
|
|
@@ -169,6 +187,9 @@ function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
|
|
|
169
187
|
let result;
|
|
170
188
|
try {
|
|
171
189
|
result = plugin.compileSFCTemplate?.(base.lang, base.content, options);
|
|
190
|
+
if (result) {
|
|
191
|
+
updateInlineTsAsts(result.ast, cache?.result.ast);
|
|
192
|
+
}
|
|
172
193
|
}
|
|
173
194
|
catch (e) {
|
|
174
195
|
const err = e;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/language-core",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"optional": true
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "17e3beabc13e9eb59a82fb1a9f0252fd6685e444"
|
|
39
39
|
}
|