@vue/language-core 1.8.18 → 1.8.20
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/out/generators/script.d.ts +2 -1
- package/out/generators/script.js +165 -147
- package/out/generators/template.d.ts +2 -2
- package/out/generators/template.js +62 -69
- package/out/index.d.ts +1 -1
- package/out/index.js +1 -1
- package/out/languageModule.d.ts +1 -1
- package/out/languageModule.js +2 -2
- package/out/parsers/scriptRanges.js +1 -1
- package/out/parsers/scriptSetupRanges.d.ts +27 -14
- package/out/parsers/scriptSetupRanges.js +65 -70
- package/out/plugins/vue-tsx.d.ts +36 -23
- package/out/plugins/vue-tsx.js +51 -31
- package/out/plugins.d.ts +1 -1
- package/out/types.d.ts +21 -6
- package/out/utils/globalTypes.js +7 -0
- package/out/utils/transform.d.ts +2 -2
- package/out/utils/transform.js +14 -14
- package/out/virtualFile/computedFiles.d.ts +4 -0
- package/out/virtualFile/computedFiles.js +227 -0
- package/out/virtualFile/computedMappings.d.ts +6 -0
- package/out/virtualFile/computedMappings.js +62 -0
- package/out/virtualFile/computedSfc.d.ts +5 -0
- package/out/virtualFile/computedSfc.js +197 -0
- package/out/virtualFile/computedVueSfc.d.ts +5 -0
- package/out/virtualFile/computedVueSfc.js +41 -0
- package/out/virtualFile/embeddedFile.d.ts +13 -0
- package/out/virtualFile/embeddedFile.js +16 -0
- package/out/virtualFile/vueFile.d.ts +28 -0
- package/out/virtualFile/vueFile.js +53 -0
- package/package.json +5 -5
- package/out/sourceFile.d.ts +0 -79
- package/out/sourceFile.js +0 -527
package/out/generators/script.js
CHANGED
|
@@ -30,16 +30,13 @@ const muggle = __importStar(require("muggle-string"));
|
|
|
30
30
|
const path_1 = require("path");
|
|
31
31
|
const shared_1 = require("../utils/shared");
|
|
32
32
|
const transform_1 = require("../utils/transform");
|
|
33
|
-
function generate(ts, fileName,
|
|
33
|
+
function generate(ts, fileName, script, scriptSetup, styles, // TODO: computed it
|
|
34
|
+
lang, scriptRanges, scriptSetupRanges, htmlGen, compilerOptions, vueCompilerOptions, codegenStack) {
|
|
34
35
|
const [codes, codeStacks] = codegenStack ? muggle.track([]) : [[], []];
|
|
35
36
|
const mirrorBehaviorMappings = [];
|
|
36
37
|
//#region monkey fix: https://github.com/vuejs/language-tools/pull/2113
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
scriptSetup: _sfc.scriptSetup,
|
|
40
|
-
};
|
|
41
|
-
if (!sfc.script && !sfc.scriptSetup) {
|
|
42
|
-
sfc.scriptSetup = {
|
|
38
|
+
if (!script && !scriptSetup) {
|
|
39
|
+
scriptSetup = {
|
|
43
40
|
content: '',
|
|
44
41
|
lang: 'ts',
|
|
45
42
|
name: '',
|
|
@@ -50,31 +47,23 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
50
47
|
generic: undefined,
|
|
51
48
|
genericOffset: 0,
|
|
52
49
|
attrs: {},
|
|
50
|
+
ast: ts.createSourceFile('', '', ts.ScriptTarget.Latest, false, ts.ScriptKind.TS),
|
|
53
51
|
};
|
|
54
52
|
scriptSetupRanges = {
|
|
55
53
|
bindings: [],
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
importSectionEndOffset: 0,
|
|
61
|
-
withDefaults: undefined,
|
|
62
|
-
defineProps: undefined,
|
|
63
|
-
defineSlots: undefined,
|
|
64
|
-
defineEmits: undefined,
|
|
65
|
-
defineExpose: undefined,
|
|
66
|
-
slotsAssignName: undefined,
|
|
67
|
-
propsAssignName: undefined,
|
|
68
|
-
propsRuntimeArg: undefined,
|
|
69
|
-
propsTypeArg: undefined,
|
|
70
|
-
withDefaultsArg: undefined,
|
|
54
|
+
props: {},
|
|
55
|
+
emits: {},
|
|
56
|
+
expose: {},
|
|
57
|
+
slots: {},
|
|
71
58
|
defineProp: [],
|
|
59
|
+
importSectionEndOffset: 0,
|
|
60
|
+
leadingCommentEndOffset: 0,
|
|
72
61
|
};
|
|
73
62
|
}
|
|
74
63
|
//#endregion
|
|
75
64
|
const bindingNames = new Set([
|
|
76
|
-
...scriptRanges?.bindings.map(range =>
|
|
77
|
-
...scriptSetupRanges?.bindings.map(range =>
|
|
65
|
+
...scriptRanges?.bindings.map(range => script.content.substring(range.start, range.end)) ?? [],
|
|
66
|
+
...scriptSetupRanges?.bindings.map(range => scriptSetup.content.substring(range.start, range.end)) ?? [],
|
|
78
67
|
]);
|
|
79
68
|
const bypassDefineComponent = lang === 'js' || lang === 'jsx';
|
|
80
69
|
const usedHelperTypes = {
|
|
@@ -94,12 +83,12 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
94
83
|
if (!generatedTemplate) {
|
|
95
84
|
generateTemplate(false);
|
|
96
85
|
}
|
|
97
|
-
if (
|
|
86
|
+
if (scriptSetup) {
|
|
98
87
|
// for code action edits
|
|
99
88
|
codes.push([
|
|
100
89
|
'',
|
|
101
90
|
'scriptSetup',
|
|
102
|
-
|
|
91
|
+
scriptSetup.content.length,
|
|
103
92
|
{},
|
|
104
93
|
]);
|
|
105
94
|
}
|
|
@@ -127,7 +116,7 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
127
116
|
};\n`);
|
|
128
117
|
}
|
|
129
118
|
if (usedHelperTypes.WithTemplateSlots) {
|
|
130
|
-
codes.push(`type __VLS_WithTemplateSlots<T, S> = T & { new(): {\n`, `$
|
|
119
|
+
codes.push(`type __VLS_WithTemplateSlots<T, S> = T & { new(): {\n`, `${(0, shared_1.getSlotsPropertyName)(vueCompilerOptions.target)}: S;\n`);
|
|
131
120
|
if (vueCompilerOptions.jsxSlots) {
|
|
132
121
|
usedHelperTypes.PropsChildren = true;
|
|
133
122
|
codes.push(`$props: __VLS_PropsChildren<S>;\n`);
|
|
@@ -139,9 +128,9 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
139
128
|
}
|
|
140
129
|
}
|
|
141
130
|
function generateSrc() {
|
|
142
|
-
if (!
|
|
131
|
+
if (!script?.src)
|
|
143
132
|
return;
|
|
144
|
-
let src =
|
|
133
|
+
let src = script.src;
|
|
145
134
|
if (src.endsWith('.d.ts'))
|
|
146
135
|
src = src.substring(0, src.length - '.d.ts'.length);
|
|
147
136
|
else if (src.endsWith('.ts'))
|
|
@@ -154,23 +143,23 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
154
143
|
codes.push([
|
|
155
144
|
`'${src}'`,
|
|
156
145
|
'script',
|
|
157
|
-
[
|
|
146
|
+
[script.srcOffset - 1, script.srcOffset + script.src.length + 1],
|
|
158
147
|
{
|
|
159
148
|
...language_core_1.FileRangeCapabilities.full,
|
|
160
|
-
rename: src ===
|
|
149
|
+
rename: src === script.src ? true : {
|
|
161
150
|
normalize: undefined,
|
|
162
151
|
apply(newName) {
|
|
163
152
|
if (newName.endsWith('.jsx')
|
|
164
153
|
|| newName.endsWith('.js')) {
|
|
165
154
|
newName = newName.split('.').slice(0, -1).join('.');
|
|
166
155
|
}
|
|
167
|
-
if (
|
|
156
|
+
if (script?.src?.endsWith('.d.ts')) {
|
|
168
157
|
newName = newName + '.d.ts';
|
|
169
158
|
}
|
|
170
|
-
else if (
|
|
159
|
+
else if (script?.src?.endsWith('.ts')) {
|
|
171
160
|
newName = newName + '.ts';
|
|
172
161
|
}
|
|
173
|
-
else if (
|
|
162
|
+
else if (script?.src?.endsWith('.tsx')) {
|
|
174
163
|
newName = newName + '.tsx';
|
|
175
164
|
}
|
|
176
165
|
return newName;
|
|
@@ -182,15 +171,15 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
182
171
|
codes.push(`export { default } from '${src}';\n`);
|
|
183
172
|
}
|
|
184
173
|
function generateScriptContentBeforeExportDefault() {
|
|
185
|
-
if (!
|
|
174
|
+
if (!script)
|
|
186
175
|
return;
|
|
187
|
-
if (!!
|
|
176
|
+
if (!!scriptSetup && scriptRanges?.exportDefault) {
|
|
188
177
|
addVirtualCode('script', 0, scriptRanges.exportDefault.expression.start);
|
|
189
178
|
}
|
|
190
179
|
else {
|
|
191
180
|
let isExportRawObject = false;
|
|
192
181
|
if (scriptRanges?.exportDefault) {
|
|
193
|
-
isExportRawObject =
|
|
182
|
+
isExportRawObject = script.content.substring(scriptRanges.exportDefault.expression.start, scriptRanges.exportDefault.expression.end).startsWith('{');
|
|
194
183
|
}
|
|
195
184
|
if (isExportRawObject && vueCompilerOptions.optionsWrapper.length === 2 && scriptRanges?.exportDefault) {
|
|
196
185
|
addVirtualCode('script', 0, scriptRanges.exportDefault.expression.start);
|
|
@@ -216,63 +205,63 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
216
205
|
}]);
|
|
217
206
|
}
|
|
218
207
|
codes.push(vueCompilerOptions.optionsWrapper[1]);
|
|
219
|
-
addVirtualCode('script', scriptRanges.exportDefault.expression.end,
|
|
208
|
+
addVirtualCode('script', scriptRanges.exportDefault.expression.end, script.content.length);
|
|
220
209
|
}
|
|
221
210
|
else {
|
|
222
|
-
addVirtualCode('script', 0,
|
|
211
|
+
addVirtualCode('script', 0, script.content.length);
|
|
223
212
|
}
|
|
224
213
|
}
|
|
225
214
|
}
|
|
226
215
|
function generateScriptContentAfterExportDefault() {
|
|
227
|
-
if (!
|
|
216
|
+
if (!script)
|
|
228
217
|
return;
|
|
229
|
-
if (!!
|
|
230
|
-
addVirtualCode('script', scriptRanges.exportDefault.end,
|
|
218
|
+
if (!!scriptSetup && scriptRanges?.exportDefault) {
|
|
219
|
+
addVirtualCode('script', scriptRanges.exportDefault.end, script.content.length);
|
|
231
220
|
}
|
|
232
221
|
}
|
|
233
222
|
function generateScriptSetupImports() {
|
|
234
|
-
if (!
|
|
223
|
+
if (!scriptSetup)
|
|
235
224
|
return;
|
|
236
225
|
if (!scriptSetupRanges)
|
|
237
226
|
return;
|
|
238
227
|
codes.push([
|
|
239
|
-
|
|
228
|
+
scriptSetup.content.substring(0, Math.max(scriptSetupRanges.importSectionEndOffset, scriptSetupRanges.leadingCommentEndOffset)) + '\n',
|
|
240
229
|
'scriptSetup',
|
|
241
230
|
0,
|
|
242
231
|
language_core_1.FileRangeCapabilities.full,
|
|
243
232
|
]);
|
|
244
233
|
}
|
|
245
234
|
function generateExportDefaultEndMapping() {
|
|
246
|
-
if (!
|
|
235
|
+
if (!scriptSetup) {
|
|
247
236
|
return;
|
|
248
237
|
}
|
|
249
238
|
// fix https://github.com/vuejs/language-tools/issues/1127
|
|
250
239
|
codes.push([
|
|
251
240
|
'',
|
|
252
241
|
'scriptSetup',
|
|
253
|
-
|
|
242
|
+
scriptSetup.content.length,
|
|
254
243
|
{ diagnostic: true },
|
|
255
244
|
]);
|
|
256
245
|
codes.push(`\n`);
|
|
257
246
|
}
|
|
258
247
|
function generateScriptSetupAndTemplate() {
|
|
259
|
-
if (!
|
|
248
|
+
if (!scriptSetup || !scriptSetupRanges) {
|
|
260
249
|
return;
|
|
261
250
|
}
|
|
262
251
|
const definePropMirrors = {};
|
|
263
252
|
let scriptSetupGeneratedOffset;
|
|
264
|
-
if (
|
|
253
|
+
if (scriptSetup.generic) {
|
|
265
254
|
if (!scriptRanges?.exportDefault) {
|
|
266
255
|
codes.push('export default ');
|
|
267
256
|
}
|
|
268
257
|
codes.push(`(<`);
|
|
269
258
|
codes.push([
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
259
|
+
scriptSetup.generic,
|
|
260
|
+
scriptSetup.name,
|
|
261
|
+
scriptSetup.genericOffset,
|
|
273
262
|
language_core_1.FileRangeCapabilities.full,
|
|
274
263
|
]);
|
|
275
|
-
if (!
|
|
264
|
+
if (!scriptSetup.generic.endsWith(',')) {
|
|
276
265
|
codes.push(`,`);
|
|
277
266
|
}
|
|
278
267
|
codes.push(`>`);
|
|
@@ -285,13 +274,13 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
285
274
|
//#region props
|
|
286
275
|
codes.push(`const __VLS_fnComponent = `);
|
|
287
276
|
codes.push(`(await import('${vueCompilerOptions.lib}')).defineComponent({\n`);
|
|
288
|
-
if (scriptSetupRanges.
|
|
277
|
+
if (scriptSetupRanges.props.define?.arg) {
|
|
289
278
|
codes.push(`props: `);
|
|
290
|
-
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.
|
|
279
|
+
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.props.define.arg.start, scriptSetupRanges.props.define.arg.end);
|
|
291
280
|
codes.push(`,\n`);
|
|
292
281
|
}
|
|
293
|
-
if (scriptSetupRanges.
|
|
294
|
-
codes.push(`emits: ({} as __VLS_NormalizeEmits<typeof `, scriptSetupRanges.
|
|
282
|
+
if (scriptSetupRanges.emits.define) {
|
|
283
|
+
codes.push(`emits: ({} as __VLS_NormalizeEmits<typeof `, scriptSetupRanges.emits.name ?? '__VLS_emit', `>),\n`);
|
|
295
284
|
}
|
|
296
285
|
codes.push(`});\n`);
|
|
297
286
|
if (scriptSetupRanges.defineProp.length) {
|
|
@@ -299,35 +288,35 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
299
288
|
for (const defineProp of scriptSetupRanges.defineProp) {
|
|
300
289
|
if (defineProp.defaultValue) {
|
|
301
290
|
if (defineProp.name) {
|
|
302
|
-
codes.push(
|
|
291
|
+
codes.push(scriptSetup.content.substring(defineProp.name.start, defineProp.name.end));
|
|
303
292
|
}
|
|
304
293
|
else {
|
|
305
294
|
codes.push('modelValue');
|
|
306
295
|
}
|
|
307
296
|
codes.push(`: `);
|
|
308
|
-
codes.push(
|
|
297
|
+
codes.push(scriptSetup.content.substring(defineProp.defaultValue.start, defineProp.defaultValue.end));
|
|
309
298
|
codes.push(`,\n`);
|
|
310
299
|
}
|
|
311
300
|
}
|
|
312
301
|
codes.push(`};\n`);
|
|
313
302
|
}
|
|
314
303
|
codes.push(`let __VLS_fnPropsTypeOnly!: {}`); // TODO: reuse __VLS_fnPropsTypeOnly even without generic, and remove __VLS_propsOption_defineProp
|
|
315
|
-
if (scriptSetupRanges.
|
|
304
|
+
if (scriptSetupRanges.props.define?.typeArg) {
|
|
316
305
|
codes.push(` & `);
|
|
317
|
-
addVirtualCode('scriptSetup', scriptSetupRanges.
|
|
306
|
+
addVirtualCode('scriptSetup', scriptSetupRanges.props.define.typeArg.start, scriptSetupRanges.props.define.typeArg.end);
|
|
318
307
|
}
|
|
319
308
|
if (scriptSetupRanges.defineProp.length) {
|
|
320
309
|
codes.push(` & {\n`);
|
|
321
310
|
for (const defineProp of scriptSetupRanges.defineProp) {
|
|
322
311
|
let propName = 'modelValue';
|
|
323
312
|
if (defineProp.name) {
|
|
324
|
-
propName =
|
|
313
|
+
propName = scriptSetup.content.substring(defineProp.name.start, defineProp.name.end);
|
|
325
314
|
const propMirrorStart = muggle.getLength(codes);
|
|
326
315
|
definePropMirrors[propName] = [propMirrorStart, propMirrorStart + propName.length];
|
|
327
316
|
}
|
|
328
317
|
codes.push(`${propName}${defineProp.required ? '' : '?'}: `);
|
|
329
318
|
if (defineProp.type) {
|
|
330
|
-
codes.push(
|
|
319
|
+
codes.push(scriptSetup.content.substring(defineProp.type.start, defineProp.type.end));
|
|
331
320
|
}
|
|
332
321
|
else if (defineProp.defaultValue) {
|
|
333
322
|
codes.push(`typeof __VLS_defaults['`);
|
|
@@ -345,7 +334,7 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
345
334
|
codes.push(`let __VLS_fnPropsDefineComponent!: InstanceType<typeof __VLS_fnComponent>['$props']`);
|
|
346
335
|
codes.push(`;\n`);
|
|
347
336
|
codes.push(`let __VLS_fnPropsSlots!: `);
|
|
348
|
-
if (scriptSetupRanges.
|
|
337
|
+
if (scriptSetupRanges.slots.define && vueCompilerOptions.jsxSlots) {
|
|
349
338
|
usedHelperTypes.PropsChildren = true;
|
|
350
339
|
codes.push(`__VLS_PropsChildren<typeof __VLS_slots>`);
|
|
351
340
|
}
|
|
@@ -356,16 +345,16 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
356
345
|
codes.push(`let __VLS_defaultProps!: `, `import('${vueCompilerOptions.lib}').VNodeProps`, `& import('${vueCompilerOptions.lib}').AllowedComponentProps`, `& import('${vueCompilerOptions.lib}').ComponentCustomProps`, `;\n`);
|
|
357
346
|
//#endregion
|
|
358
347
|
codes.push('return {} as {\n');
|
|
359
|
-
codes.push(`props: __VLS_Prettify<
|
|
360
|
-
codes.push(`expose(exposed: import('${vueCompilerOptions.lib}').ShallowUnwrapRef<${scriptSetupRanges.
|
|
348
|
+
codes.push(`props: __VLS_Prettify<__VLS_OmitKeepDiscriminatedUnion<typeof __VLS_fnPropsDefineComponent & typeof __VLS_fnPropsTypeOnly, keyof typeof __VLS_defaultProps>> & typeof __VLS_fnPropsSlots & typeof __VLS_defaultProps,\n`);
|
|
349
|
+
codes.push(`expose(exposed: import('${vueCompilerOptions.lib}').ShallowUnwrapRef<${scriptSetupRanges.expose.define ? 'typeof __VLS_exposed' : '{}'}>): void,\n`);
|
|
361
350
|
codes.push('attrs: any,\n');
|
|
362
351
|
codes.push('slots: ReturnType<typeof __VLS_template>,\n');
|
|
363
|
-
codes.push(`emit: typeof ${scriptSetupRanges.
|
|
352
|
+
codes.push(`emit: typeof ${scriptSetupRanges.emits.name ?? '__VLS_emit'},\n`);
|
|
364
353
|
codes.push('};\n');
|
|
365
354
|
codes.push('})(),\n');
|
|
366
355
|
codes.push(`) => ({} as import('${vueCompilerOptions.lib}').VNode & { __ctx?: Awaited<typeof __VLS_setup> }))`);
|
|
367
356
|
}
|
|
368
|
-
else if (!
|
|
357
|
+
else if (!script) {
|
|
369
358
|
// no script block, generate script setup code at root
|
|
370
359
|
scriptSetupGeneratedOffset = generateSetupFunction(false, 'export', definePropMirrors);
|
|
371
360
|
}
|
|
@@ -383,7 +372,7 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
383
372
|
if (!defineProp.name) {
|
|
384
373
|
continue;
|
|
385
374
|
}
|
|
386
|
-
const propName =
|
|
375
|
+
const propName = scriptSetup.content.substring(defineProp.name.start, defineProp.name.end);
|
|
387
376
|
const propMirror = definePropMirrors[propName];
|
|
388
377
|
if (propMirror) {
|
|
389
378
|
mirrorBehaviorMappings.push({
|
|
@@ -399,11 +388,11 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
399
388
|
}
|
|
400
389
|
}
|
|
401
390
|
function generateSetupFunction(functional, mode, definePropMirrors) {
|
|
402
|
-
if (!scriptSetupRanges || !
|
|
391
|
+
if (!scriptSetupRanges || !scriptSetup) {
|
|
403
392
|
return;
|
|
404
393
|
}
|
|
405
|
-
const definePropProposalA =
|
|
406
|
-
const definePropProposalB =
|
|
394
|
+
const definePropProposalA = scriptSetup.content.trimStart().startsWith('// @experimentalDefinePropProposal=kevinEdition') || vueCompilerOptions.experimentalDefinePropProposal === 'kevinEdition';
|
|
395
|
+
const definePropProposalB = scriptSetup.content.trimStart().startsWith('// @experimentalDefinePropProposal=johnsonEdition') || vueCompilerOptions.experimentalDefinePropProposal === 'johnsonEdition';
|
|
407
396
|
if (vueCompilerOptions.target >= 3.3) {
|
|
408
397
|
codes.push('const { ');
|
|
409
398
|
for (const macro of Object.keys(vueCompilerOptions.macros)) {
|
|
@@ -429,35 +418,44 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
429
418
|
}
|
|
430
419
|
const scriptSetupGeneratedOffset = muggle.getLength(codes) - scriptSetupRanges.importSectionEndOffset;
|
|
431
420
|
let setupCodeModifies = [];
|
|
432
|
-
if (scriptSetupRanges.
|
|
433
|
-
const
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
421
|
+
if (scriptSetupRanges.props.define && !scriptSetupRanges.props.name) {
|
|
422
|
+
const range = scriptSetupRanges.props.withDefaults ?? scriptSetupRanges.props.define;
|
|
423
|
+
const statement = scriptSetupRanges.props.define.statement;
|
|
424
|
+
if (statement.start === range.start && statement.end === range.end) {
|
|
425
|
+
setupCodeModifies.push([() => codes.push(`const __VLS_props = `), range.start, range.start]);
|
|
426
|
+
}
|
|
427
|
+
else {
|
|
428
|
+
setupCodeModifies.push([() => {
|
|
429
|
+
codes.push(`const __VLS_props = `);
|
|
430
|
+
addVirtualCode('scriptSetup', range.start, range.end);
|
|
431
|
+
codes.push(`;\n`);
|
|
432
|
+
addVirtualCode('scriptSetup', statement.start, range.start);
|
|
433
|
+
codes.push(`__VLS_props`);
|
|
434
|
+
}, statement.start, range.end]);
|
|
435
|
+
}
|
|
438
436
|
}
|
|
439
|
-
if (scriptSetupRanges.
|
|
440
|
-
setupCodeModifies.push([() => codes.push(`const __VLS_slots = `), scriptSetupRanges.
|
|
437
|
+
if (scriptSetupRanges.slots.define && !scriptSetupRanges.slots.name) {
|
|
438
|
+
setupCodeModifies.push([() => codes.push(`const __VLS_slots = `), scriptSetupRanges.slots.define.start, scriptSetupRanges.slots.define.start]);
|
|
441
439
|
}
|
|
442
|
-
if (scriptSetupRanges.
|
|
443
|
-
setupCodeModifies.push([() => codes.push(`const __VLS_emit = `), scriptSetupRanges.
|
|
440
|
+
if (scriptSetupRanges.emits.define && !scriptSetupRanges.emits.name) {
|
|
441
|
+
setupCodeModifies.push([() => codes.push(`const __VLS_emit = `), scriptSetupRanges.emits.define.start, scriptSetupRanges.emits.define.start]);
|
|
444
442
|
}
|
|
445
|
-
if (scriptSetupRanges.
|
|
443
|
+
if (scriptSetupRanges.expose.define) {
|
|
446
444
|
setupCodeModifies.push([() => {
|
|
447
|
-
if (scriptSetupRanges?.
|
|
445
|
+
if (scriptSetupRanges?.expose.define?.typeArg) {
|
|
448
446
|
codes.push(`let __VLS_exposed!: `);
|
|
449
|
-
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.
|
|
447
|
+
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.expose.define.typeArg.start, scriptSetupRanges.expose.define.typeArg.end);
|
|
450
448
|
codes.push(`;\n`);
|
|
451
449
|
}
|
|
452
|
-
else if (scriptSetupRanges?.
|
|
450
|
+
else if (scriptSetupRanges?.expose.define?.arg) {
|
|
453
451
|
codes.push(`const __VLS_exposed = `);
|
|
454
|
-
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.
|
|
452
|
+
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.expose.define.arg.start, scriptSetupRanges.expose.define.arg.end);
|
|
455
453
|
codes.push(`;\n`);
|
|
456
454
|
}
|
|
457
455
|
else {
|
|
458
456
|
codes.push(`const __VLS_exposed = {};\n`);
|
|
459
457
|
}
|
|
460
|
-
}, scriptSetupRanges.
|
|
458
|
+
}, scriptSetupRanges.expose.define.start, scriptSetupRanges.expose.define.start]);
|
|
461
459
|
}
|
|
462
460
|
setupCodeModifies = setupCodeModifies.sort((a, b) => a[1] - b[1]);
|
|
463
461
|
if (setupCodeModifies.length) {
|
|
@@ -477,10 +475,10 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
477
475
|
else {
|
|
478
476
|
addVirtualCode('scriptSetup', scriptSetupRanges.importSectionEndOffset);
|
|
479
477
|
}
|
|
480
|
-
if (scriptSetupRanges.
|
|
478
|
+
if (scriptSetupRanges.props.define?.typeArg && scriptSetupRanges.props.withDefaults?.arg) {
|
|
481
479
|
// fix https://github.com/vuejs/language-tools/issues/1187
|
|
482
480
|
codes.push(`const __VLS_withDefaultsArg = (function <T>(t: T) { return t })(`);
|
|
483
|
-
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.
|
|
481
|
+
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.props.withDefaults.arg.start, scriptSetupRanges.props.withDefaults.arg.end);
|
|
484
482
|
codes.push(`);\n`);
|
|
485
483
|
}
|
|
486
484
|
if (!functional && scriptSetupRanges.defineProp.length) {
|
|
@@ -492,7 +490,7 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
492
490
|
addExtraReferenceVirtualCode('scriptSetup', defineProp.name.start, defineProp.name.end);
|
|
493
491
|
}
|
|
494
492
|
else if (defineProp.name) {
|
|
495
|
-
propName =
|
|
493
|
+
propName = scriptSetup.content.substring(defineProp.name.start, defineProp.name.end);
|
|
496
494
|
const start = muggle.getLength(codes);
|
|
497
495
|
definePropMirrors[propName] = [start, start + propName.length];
|
|
498
496
|
codes.push(propName);
|
|
@@ -506,7 +504,7 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
506
504
|
type = `NonNullable<typeof ${propName}['value']>`;
|
|
507
505
|
}
|
|
508
506
|
else if (defineProp.type) {
|
|
509
|
-
type =
|
|
507
|
+
type = scriptSetup.content.substring(defineProp.type.start, defineProp.type.end);
|
|
510
508
|
}
|
|
511
509
|
if (defineProp.required) {
|
|
512
510
|
codes.push(`{ required: true, type: import('${vueCompilerOptions.lib}').PropType<${type}> },\n`);
|
|
@@ -519,7 +517,7 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
519
517
|
}
|
|
520
518
|
generateTemplate(functional);
|
|
521
519
|
if (mode === 'return' || mode === 'export') {
|
|
522
|
-
if (!vueCompilerOptions.skipTemplateCodegen && (htmlGen?.hasSlot || scriptSetupRanges?.
|
|
520
|
+
if (!vueCompilerOptions.skipTemplateCodegen && (htmlGen?.hasSlot || scriptSetupRanges?.slots.define)) {
|
|
523
521
|
usedHelperTypes.WithTemplateSlots = true;
|
|
524
522
|
codes.push(`const __VLS_component = `);
|
|
525
523
|
generateComponent(functional);
|
|
@@ -553,7 +551,7 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
553
551
|
codes.push(`setup() {\n`);
|
|
554
552
|
codes.push(`return {\n`);
|
|
555
553
|
generateSetupReturns();
|
|
556
|
-
if (scriptSetupRanges.
|
|
554
|
+
if (scriptSetupRanges.expose.define) {
|
|
557
555
|
codes.push(`...__VLS_exposed,\n`);
|
|
558
556
|
}
|
|
559
557
|
codes.push(`};\n`);
|
|
@@ -562,17 +560,20 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
562
560
|
}
|
|
563
561
|
function generateComponentOptions(functional) {
|
|
564
562
|
if (scriptSetupRanges && !bypassDefineComponent) {
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
}
|
|
572
|
-
|
|
563
|
+
const ranges = scriptSetupRanges;
|
|
564
|
+
const propsCodegens = [];
|
|
565
|
+
if (ranges.props.define?.arg) {
|
|
566
|
+
const arg = ranges.props.define.arg;
|
|
567
|
+
propsCodegens.push(() => {
|
|
568
|
+
addExtraReferenceVirtualCode('scriptSetup', arg.start, arg.end);
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
if (ranges.props.define?.typeArg) {
|
|
572
|
+
const typeArg = ranges.props.define.typeArg;
|
|
573
|
+
propsCodegens.push(() => {
|
|
573
574
|
usedHelperTypes.DefinePropsToOptions = true;
|
|
574
|
-
codes.push(
|
|
575
|
-
if (
|
|
575
|
+
codes.push(`{} as `);
|
|
576
|
+
if (ranges.props.withDefaults?.arg) {
|
|
576
577
|
usedHelperTypes.MergePropDefaults = true;
|
|
577
578
|
codes.push(`__VLS_WithDefaults<`);
|
|
578
579
|
}
|
|
@@ -581,22 +582,38 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
581
582
|
codes.push(`typeof __VLS_fnPropsTypeOnly`);
|
|
582
583
|
}
|
|
583
584
|
else {
|
|
584
|
-
addExtraReferenceVirtualCode('scriptSetup',
|
|
585
|
+
addExtraReferenceVirtualCode('scriptSetup', typeArg.start, typeArg.end);
|
|
585
586
|
}
|
|
586
587
|
codes.push(`>`);
|
|
587
|
-
if (
|
|
588
|
+
if (ranges.props.withDefaults?.arg) {
|
|
588
589
|
codes.push(`, typeof __VLS_withDefaultsArg`);
|
|
589
590
|
codes.push(`>`);
|
|
590
591
|
}
|
|
591
|
-
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
if (!functional && ranges.defineProp.length) {
|
|
595
|
+
propsCodegens.push(() => {
|
|
596
|
+
codes.push(`__VLS_propsOption_defineProp`);
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
if (propsCodegens.length === 1) {
|
|
600
|
+
codes.push(`props: `);
|
|
601
|
+
for (const generate of propsCodegens) {
|
|
602
|
+
generate();
|
|
592
603
|
}
|
|
593
|
-
|
|
594
|
-
|
|
604
|
+
codes.push(`,\n`);
|
|
605
|
+
}
|
|
606
|
+
else if (propsCodegens.length >= 2) {
|
|
607
|
+
codes.push(`props: {\n`);
|
|
608
|
+
for (const generate of propsCodegens) {
|
|
609
|
+
codes.push('...');
|
|
610
|
+
generate();
|
|
611
|
+
codes.push(',\n');
|
|
595
612
|
}
|
|
596
613
|
codes.push(`},\n`);
|
|
597
614
|
}
|
|
598
|
-
if (
|
|
599
|
-
codes.push(`emits: ({} as __VLS_NormalizeEmits<typeof `,
|
|
615
|
+
if (ranges.emits.define) {
|
|
616
|
+
codes.push(`emits: ({} as __VLS_NormalizeEmits<typeof `, ranges.emits.name ?? '__VLS_emit', `>),\n`);
|
|
600
617
|
}
|
|
601
618
|
}
|
|
602
619
|
if (scriptRanges?.exportDefault?.args) {
|
|
@@ -606,14 +623,14 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
606
623
|
function generateSetupReturns() {
|
|
607
624
|
if (scriptSetupRanges && bypassDefineComponent) {
|
|
608
625
|
// fill $props
|
|
609
|
-
if (scriptSetupRanges.
|
|
626
|
+
if (scriptSetupRanges.props.define) {
|
|
610
627
|
// NOTE: defineProps is inaccurate for $props
|
|
611
|
-
codes.push(`$props: __VLS_makeOptional(${scriptSetupRanges.
|
|
612
|
-
codes.push(`...${scriptSetupRanges.
|
|
628
|
+
codes.push(`$props: __VLS_makeOptional(${scriptSetupRanges.props.name ?? `__VLS_props`}),\n`);
|
|
629
|
+
codes.push(`...${scriptSetupRanges.props.name ?? `__VLS_props`},\n`);
|
|
613
630
|
}
|
|
614
631
|
// fill $emit
|
|
615
|
-
if (scriptSetupRanges.
|
|
616
|
-
codes.push(`$emit: ${scriptSetupRanges.
|
|
632
|
+
if (scriptSetupRanges.emits.define) {
|
|
633
|
+
codes.push(`$emit: ${scriptSetupRanges.emits.name ?? '__VLS_emit'},\n`);
|
|
617
634
|
}
|
|
618
635
|
}
|
|
619
636
|
}
|
|
@@ -637,7 +654,7 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
637
654
|
}
|
|
638
655
|
}
|
|
639
656
|
function generateComponentForTemplateUsage(functional, cssIds) {
|
|
640
|
-
if (
|
|
657
|
+
if (scriptSetup && scriptSetupRanges) {
|
|
641
658
|
codes.push(`const __VLS_internalComponent = (await import('${vueCompilerOptions.lib}')).defineComponent({\n`);
|
|
642
659
|
generateComponentOptions(functional);
|
|
643
660
|
codes.push(`setup() {\n`);
|
|
@@ -646,9 +663,9 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
646
663
|
// bindings
|
|
647
664
|
const templateUsageVars = getTemplateUsageVars();
|
|
648
665
|
for (const [content, bindings] of [
|
|
649
|
-
[
|
|
650
|
-
scriptRanges &&
|
|
651
|
-
? [
|
|
666
|
+
[scriptSetup.content, scriptSetupRanges.bindings],
|
|
667
|
+
scriptRanges && script
|
|
668
|
+
? [script.content, scriptRanges.bindings]
|
|
652
669
|
: ['', []],
|
|
653
670
|
]) {
|
|
654
671
|
for (const expose of bindings) {
|
|
@@ -678,7 +695,7 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
678
695
|
codes.push(`},\n`); // setup() {
|
|
679
696
|
codes.push(`});\n`); // defineComponent({
|
|
680
697
|
}
|
|
681
|
-
else if (
|
|
698
|
+
else if (script) {
|
|
682
699
|
codes.push(`let __VLS_internalComponent!: typeof import('./${path_1.posix.basename(fileName)}')['default'];\n`);
|
|
683
700
|
}
|
|
684
701
|
else {
|
|
@@ -688,10 +705,10 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
688
705
|
function generateExportOptions() {
|
|
689
706
|
codes.push(`\n`);
|
|
690
707
|
codes.push(`const __VLS_componentsOption = `);
|
|
691
|
-
if (
|
|
708
|
+
if (script && scriptRanges?.exportDefault?.componentsOption) {
|
|
692
709
|
const componentsOption = scriptRanges.exportDefault.componentsOption;
|
|
693
710
|
codes.push([
|
|
694
|
-
|
|
711
|
+
script.content.substring(componentsOption.start, componentsOption.end),
|
|
695
712
|
'script',
|
|
696
713
|
componentsOption.start,
|
|
697
714
|
{
|
|
@@ -707,13 +724,13 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
707
724
|
}
|
|
708
725
|
function generateConstNameOption() {
|
|
709
726
|
codes.push(`\n`);
|
|
710
|
-
if (
|
|
727
|
+
if (script && scriptRanges?.exportDefault?.nameOption) {
|
|
711
728
|
const nameOption = scriptRanges.exportDefault.nameOption;
|
|
712
729
|
codes.push(`const __VLS_name = `);
|
|
713
|
-
codes.push(`${
|
|
730
|
+
codes.push(`${script.content.substring(nameOption.start, nameOption.end)} as const`);
|
|
714
731
|
codes.push(`;\n`);
|
|
715
732
|
}
|
|
716
|
-
else if (
|
|
733
|
+
else if (scriptSetup) {
|
|
717
734
|
codes.push(`let __VLS_name!: '${path_1.posix.basename(fileName.substring(0, fileName.lastIndexOf('.')))}';\n`);
|
|
718
735
|
}
|
|
719
736
|
else {
|
|
@@ -725,32 +742,33 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
725
742
|
codes.push(`let __VLS_ctx!: ${useGlobalThisTypeInCtx ? 'typeof globalThis &' : ''}`);
|
|
726
743
|
codes.push(`InstanceType<__VLS_PickNotAny<typeof __VLS_internalComponent, new () => {}>> & {\n`);
|
|
727
744
|
/* CSS Module */
|
|
728
|
-
for (let i = 0; i <
|
|
729
|
-
const style =
|
|
730
|
-
if (
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
745
|
+
for (let i = 0; i < styles.length; i++) {
|
|
746
|
+
const style = styles[i];
|
|
747
|
+
if (style.module) {
|
|
748
|
+
codes.push(`${style.module}: Record<string, string> & __VLS_Prettify<{}`);
|
|
749
|
+
for (const className of style.classNames) {
|
|
750
|
+
generateCssClassProperty(i, className.text.substring(1), { start: className.offset, end: className.offset + className.text.length }, 'string', false, true);
|
|
751
|
+
}
|
|
752
|
+
codes.push('>;\n');
|
|
735
753
|
}
|
|
736
|
-
codes.push('>;\n');
|
|
737
754
|
}
|
|
738
755
|
codes.push(`};\n`);
|
|
739
756
|
/* Components */
|
|
740
757
|
codes.push('/* Components */\n');
|
|
741
758
|
codes.push(`let __VLS_otherComponents!: NonNullable<typeof __VLS_internalComponent extends { components: infer C } ? C : {}> & typeof __VLS_componentsOption;\n`);
|
|
742
|
-
codes.push(`let __VLS_own!: __VLS_SelfComponent<typeof __VLS_name, typeof __VLS_internalComponent & (new () => { ${(0, shared_1.getSlotsPropertyName)(vueCompilerOptions.target)}: typeof ${scriptSetupRanges?.
|
|
759
|
+
codes.push(`let __VLS_own!: __VLS_SelfComponent<typeof __VLS_name, typeof __VLS_internalComponent & (new () => { ${(0, shared_1.getSlotsPropertyName)(vueCompilerOptions.target)}: typeof ${scriptSetupRanges?.slots?.name ?? '__VLS_slots'} })>;\n`);
|
|
743
760
|
codes.push(`let __VLS_localComponents!: typeof __VLS_otherComponents & Omit<typeof __VLS_own, keyof typeof __VLS_otherComponents>;\n`);
|
|
744
761
|
codes.push(`let __VLS_components!: typeof __VLS_localComponents & __VLS_GlobalComponents & typeof __VLS_ctx;\n`); // for html completion, TS references...
|
|
745
762
|
/* Style Scoped */
|
|
746
763
|
codes.push('/* Style Scoped */\n');
|
|
747
764
|
codes.push('type __VLS_StyleScopedClasses = {}');
|
|
748
|
-
for (let i = 0; i <
|
|
749
|
-
const style =
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
765
|
+
for (let i = 0; i < styles.length; i++) {
|
|
766
|
+
const style = styles[i];
|
|
767
|
+
const option = vueCompilerOptions.experimentalResolveStyleCssClasses;
|
|
768
|
+
if ((option === 'always' || option === 'scoped') && style.scoped) {
|
|
769
|
+
for (const className of style.classNames) {
|
|
770
|
+
generateCssClassProperty(i, className.text.substring(1), { start: className.offset, end: className.offset + className.text.length }, 'boolean', true, !style.module);
|
|
771
|
+
}
|
|
754
772
|
}
|
|
755
773
|
}
|
|
756
774
|
codes.push(';\n');
|
|
@@ -770,11 +788,11 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
770
788
|
}
|
|
771
789
|
if (!htmlGen) {
|
|
772
790
|
codes.push(`// no template\n`);
|
|
773
|
-
if (!scriptSetupRanges?.
|
|
791
|
+
if (!scriptSetupRanges?.slots.define) {
|
|
774
792
|
codes.push(`const __VLS_slots = {};\n`);
|
|
775
793
|
}
|
|
776
794
|
}
|
|
777
|
-
codes.push(`return ${scriptSetupRanges?.
|
|
795
|
+
codes.push(`return ${scriptSetupRanges?.slots.name ?? '__VLS_slots'};\n`);
|
|
778
796
|
return { cssIds };
|
|
779
797
|
function generateCssClassProperty(styleIndex, className, classRange, propertyType, optional, referencesCodeLens) {
|
|
780
798
|
codes.push(`\n & { `);
|
|
@@ -811,9 +829,9 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
811
829
|
codes.push(` }`);
|
|
812
830
|
}
|
|
813
831
|
function generateCssVars() {
|
|
814
|
-
const emptyLocalVars =
|
|
832
|
+
const emptyLocalVars = new Map();
|
|
815
833
|
const identifiers = new Set();
|
|
816
|
-
for (const style of
|
|
834
|
+
for (const style of styles) {
|
|
817
835
|
for (const cssBind of style.cssVars) {
|
|
818
836
|
(0, transform_1.walkInterpolationFragment)(ts, cssBind.text, ts.createSourceFile('/a.txt', cssBind.text, ts.ScriptTarget.ESNext), (frag, fragOffset, onlyForErrorMapping) => {
|
|
819
837
|
if (fragOffset === undefined) {
|
|
@@ -850,7 +868,7 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
850
868
|
usageVars.add(tag.split('.')[0]);
|
|
851
869
|
}
|
|
852
870
|
}
|
|
853
|
-
for (const _id of htmlGen.
|
|
871
|
+
for (const _id of htmlGen.accessedGlobalVariables) {
|
|
854
872
|
usageVars.add(_id);
|
|
855
873
|
}
|
|
856
874
|
}
|
|
@@ -859,7 +877,7 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
859
877
|
function addVirtualCode(vueTag, start, end) {
|
|
860
878
|
muggle.offsetStack();
|
|
861
879
|
codes.push([
|
|
862
|
-
|
|
880
|
+
(vueTag === 'script' ? script : scriptSetup).content.substring(start, end),
|
|
863
881
|
vueTag,
|
|
864
882
|
start,
|
|
865
883
|
language_core_1.FileRangeCapabilities.full, // diagnostic also working for setup() returns unused in template checking
|
|
@@ -869,7 +887,7 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
869
887
|
function addExtraReferenceVirtualCode(vueTag, start, end) {
|
|
870
888
|
muggle.offsetStack();
|
|
871
889
|
codes.push([
|
|
872
|
-
|
|
890
|
+
(vueTag === 'script' ? script : scriptSetup).content.substring(start, end),
|
|
873
891
|
vueTag,
|
|
874
892
|
start,
|
|
875
893
|
{
|