@vue/language-core 1.8.19 → 1.8.21
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 +112 -117
- package/out/generators/template.d.ts +1 -1
- package/out/generators/template.js +54 -83
- package/out/index.d.ts +1 -1
- package/out/index.js +3 -15
- package/out/languageModule.d.ts +1 -1
- package/out/languageModule.js +3 -26
- package/out/plugins/vue-tsx.d.ts +9 -9
- package/out/plugins/vue-tsx.js +49 -52
- package/out/plugins.d.ts +1 -1
- package/out/plugins.js +11 -37
- package/out/types.d.ts +21 -6
- package/out/utils/globalTypes.js +7 -0
- package/out/utils/parseSfc.js +1 -24
- package/out/utils/transform.d.ts +1 -1
- package/out/utils/transform.js +8 -8
- package/out/utils/ts.js +1 -24
- package/out/utils/vue2TemplateCompiler.js +1 -24
- package/out/virtualFile/computedFiles.d.ts +4 -0
- package/out/virtualFile/computedFiles.js +204 -0
- package/out/virtualFile/computedMappings.d.ts +6 -0
- package/out/virtualFile/computedMappings.js +39 -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 +6 -6
- package/out/sourceFile.d.ts +0 -79
- package/out/sourceFile.js +0 -527
|
@@ -6,7 +6,8 @@ import type { ScriptRanges } from '../parsers/scriptRanges';
|
|
|
6
6
|
import type { ScriptSetupRanges } from '../parsers/scriptSetupRanges';
|
|
7
7
|
import type { VueCompilerOptions } from '../types';
|
|
8
8
|
import { Sfc } from '../types';
|
|
9
|
-
export declare function generate(ts: typeof import('typescript/lib/tsserverlibrary'), fileName: string,
|
|
9
|
+
export declare function generate(ts: typeof import('typescript/lib/tsserverlibrary'), fileName: string, script: Sfc['script'], scriptSetup: Sfc['scriptSetup'], styles: Sfc['styles'], // TODO: computed it
|
|
10
|
+
lang: string, scriptRanges: ScriptRanges | undefined, scriptSetupRanges: ScriptSetupRanges | undefined, htmlGen: ReturnType<typeof templateGen['generate']> | undefined, compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions, codegenStack: boolean): {
|
|
10
11
|
codes: SourceMaps.Segment<FileRangeCapabilities>[];
|
|
11
12
|
codeStacks: SourceMaps.StackNode[];
|
|
12
13
|
mirrorBehaviorMappings: SourceMaps.Mapping<[MirrorBehaviorCapabilities, MirrorBehaviorCapabilities]>[];
|
package/out/generators/script.js
CHANGED
|
@@ -1,45 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.generate = void 0;
|
|
27
4
|
const language_core_1 = require("@volar/language-core");
|
|
28
5
|
const source_map_1 = require("@volar/source-map");
|
|
29
|
-
const muggle =
|
|
6
|
+
const muggle = require("muggle-string");
|
|
30
7
|
const path_1 = require("path");
|
|
31
8
|
const shared_1 = require("../utils/shared");
|
|
32
9
|
const transform_1 = require("../utils/transform");
|
|
33
|
-
function generate(ts, fileName,
|
|
10
|
+
function generate(ts, fileName, script, scriptSetup, styles, // TODO: computed it
|
|
11
|
+
lang, scriptRanges, scriptSetupRanges, htmlGen, compilerOptions, vueCompilerOptions, codegenStack) {
|
|
34
12
|
const [codes, codeStacks] = codegenStack ? muggle.track([]) : [[], []];
|
|
35
13
|
const mirrorBehaviorMappings = [];
|
|
36
14
|
//#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 = {
|
|
15
|
+
if (!script && !scriptSetup) {
|
|
16
|
+
scriptSetup = {
|
|
43
17
|
content: '',
|
|
44
18
|
lang: 'ts',
|
|
45
19
|
name: '',
|
|
@@ -50,6 +24,7 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
50
24
|
generic: undefined,
|
|
51
25
|
genericOffset: 0,
|
|
52
26
|
attrs: {},
|
|
27
|
+
ast: ts.createSourceFile('', '', ts.ScriptTarget.Latest, false, ts.ScriptKind.TS),
|
|
53
28
|
};
|
|
54
29
|
scriptSetupRanges = {
|
|
55
30
|
bindings: [],
|
|
@@ -64,8 +39,8 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
64
39
|
}
|
|
65
40
|
//#endregion
|
|
66
41
|
const bindingNames = new Set([
|
|
67
|
-
...scriptRanges?.bindings.map(range =>
|
|
68
|
-
...scriptSetupRanges?.bindings.map(range =>
|
|
42
|
+
...scriptRanges?.bindings.map(range => script.content.substring(range.start, range.end)) ?? [],
|
|
43
|
+
...scriptSetupRanges?.bindings.map(range => scriptSetup.content.substring(range.start, range.end)) ?? [],
|
|
69
44
|
]);
|
|
70
45
|
const bypassDefineComponent = lang === 'js' || lang === 'jsx';
|
|
71
46
|
const usedHelperTypes = {
|
|
@@ -85,12 +60,12 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
85
60
|
if (!generatedTemplate) {
|
|
86
61
|
generateTemplate(false);
|
|
87
62
|
}
|
|
88
|
-
if (
|
|
63
|
+
if (scriptSetup) {
|
|
89
64
|
// for code action edits
|
|
90
65
|
codes.push([
|
|
91
66
|
'',
|
|
92
67
|
'scriptSetup',
|
|
93
|
-
|
|
68
|
+
scriptSetup.content.length,
|
|
94
69
|
{},
|
|
95
70
|
]);
|
|
96
71
|
}
|
|
@@ -118,7 +93,7 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
118
93
|
};\n`);
|
|
119
94
|
}
|
|
120
95
|
if (usedHelperTypes.WithTemplateSlots) {
|
|
121
|
-
codes.push(`type __VLS_WithTemplateSlots<T, S> = T & { new(): {\n`, `$
|
|
96
|
+
codes.push(`type __VLS_WithTemplateSlots<T, S> = T & { new(): {\n`, `${(0, shared_1.getSlotsPropertyName)(vueCompilerOptions.target)}: S;\n`);
|
|
122
97
|
if (vueCompilerOptions.jsxSlots) {
|
|
123
98
|
usedHelperTypes.PropsChildren = true;
|
|
124
99
|
codes.push(`$props: __VLS_PropsChildren<S>;\n`);
|
|
@@ -130,9 +105,9 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
130
105
|
}
|
|
131
106
|
}
|
|
132
107
|
function generateSrc() {
|
|
133
|
-
if (!
|
|
108
|
+
if (!script?.src)
|
|
134
109
|
return;
|
|
135
|
-
let src =
|
|
110
|
+
let src = script.src;
|
|
136
111
|
if (src.endsWith('.d.ts'))
|
|
137
112
|
src = src.substring(0, src.length - '.d.ts'.length);
|
|
138
113
|
else if (src.endsWith('.ts'))
|
|
@@ -145,23 +120,23 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
145
120
|
codes.push([
|
|
146
121
|
`'${src}'`,
|
|
147
122
|
'script',
|
|
148
|
-
[
|
|
123
|
+
[script.srcOffset - 1, script.srcOffset + script.src.length + 1],
|
|
149
124
|
{
|
|
150
125
|
...language_core_1.FileRangeCapabilities.full,
|
|
151
|
-
rename: src ===
|
|
126
|
+
rename: src === script.src ? true : {
|
|
152
127
|
normalize: undefined,
|
|
153
128
|
apply(newName) {
|
|
154
129
|
if (newName.endsWith('.jsx')
|
|
155
130
|
|| newName.endsWith('.js')) {
|
|
156
131
|
newName = newName.split('.').slice(0, -1).join('.');
|
|
157
132
|
}
|
|
158
|
-
if (
|
|
133
|
+
if (script?.src?.endsWith('.d.ts')) {
|
|
159
134
|
newName = newName + '.d.ts';
|
|
160
135
|
}
|
|
161
|
-
else if (
|
|
136
|
+
else if (script?.src?.endsWith('.ts')) {
|
|
162
137
|
newName = newName + '.ts';
|
|
163
138
|
}
|
|
164
|
-
else if (
|
|
139
|
+
else if (script?.src?.endsWith('.tsx')) {
|
|
165
140
|
newName = newName + '.tsx';
|
|
166
141
|
}
|
|
167
142
|
return newName;
|
|
@@ -173,15 +148,15 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
173
148
|
codes.push(`export { default } from '${src}';\n`);
|
|
174
149
|
}
|
|
175
150
|
function generateScriptContentBeforeExportDefault() {
|
|
176
|
-
if (!
|
|
151
|
+
if (!script)
|
|
177
152
|
return;
|
|
178
|
-
if (!!
|
|
153
|
+
if (!!scriptSetup && scriptRanges?.exportDefault) {
|
|
179
154
|
addVirtualCode('script', 0, scriptRanges.exportDefault.expression.start);
|
|
180
155
|
}
|
|
181
156
|
else {
|
|
182
157
|
let isExportRawObject = false;
|
|
183
158
|
if (scriptRanges?.exportDefault) {
|
|
184
|
-
isExportRawObject =
|
|
159
|
+
isExportRawObject = script.content.substring(scriptRanges.exportDefault.expression.start, scriptRanges.exportDefault.expression.end).startsWith('{');
|
|
185
160
|
}
|
|
186
161
|
if (isExportRawObject && vueCompilerOptions.optionsWrapper.length === 2 && scriptRanges?.exportDefault) {
|
|
187
162
|
addVirtualCode('script', 0, scriptRanges.exportDefault.expression.start);
|
|
@@ -207,63 +182,63 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
207
182
|
}]);
|
|
208
183
|
}
|
|
209
184
|
codes.push(vueCompilerOptions.optionsWrapper[1]);
|
|
210
|
-
addVirtualCode('script', scriptRanges.exportDefault.expression.end,
|
|
185
|
+
addVirtualCode('script', scriptRanges.exportDefault.expression.end, script.content.length);
|
|
211
186
|
}
|
|
212
187
|
else {
|
|
213
|
-
addVirtualCode('script', 0,
|
|
188
|
+
addVirtualCode('script', 0, script.content.length);
|
|
214
189
|
}
|
|
215
190
|
}
|
|
216
191
|
}
|
|
217
192
|
function generateScriptContentAfterExportDefault() {
|
|
218
|
-
if (!
|
|
193
|
+
if (!script)
|
|
219
194
|
return;
|
|
220
|
-
if (!!
|
|
221
|
-
addVirtualCode('script', scriptRanges.exportDefault.end,
|
|
195
|
+
if (!!scriptSetup && scriptRanges?.exportDefault) {
|
|
196
|
+
addVirtualCode('script', scriptRanges.exportDefault.end, script.content.length);
|
|
222
197
|
}
|
|
223
198
|
}
|
|
224
199
|
function generateScriptSetupImports() {
|
|
225
|
-
if (!
|
|
200
|
+
if (!scriptSetup)
|
|
226
201
|
return;
|
|
227
202
|
if (!scriptSetupRanges)
|
|
228
203
|
return;
|
|
229
204
|
codes.push([
|
|
230
|
-
|
|
205
|
+
scriptSetup.content.substring(0, Math.max(scriptSetupRanges.importSectionEndOffset, scriptSetupRanges.leadingCommentEndOffset)) + '\n',
|
|
231
206
|
'scriptSetup',
|
|
232
207
|
0,
|
|
233
208
|
language_core_1.FileRangeCapabilities.full,
|
|
234
209
|
]);
|
|
235
210
|
}
|
|
236
211
|
function generateExportDefaultEndMapping() {
|
|
237
|
-
if (!
|
|
212
|
+
if (!scriptSetup) {
|
|
238
213
|
return;
|
|
239
214
|
}
|
|
240
215
|
// fix https://github.com/vuejs/language-tools/issues/1127
|
|
241
216
|
codes.push([
|
|
242
217
|
'',
|
|
243
218
|
'scriptSetup',
|
|
244
|
-
|
|
219
|
+
scriptSetup.content.length,
|
|
245
220
|
{ diagnostic: true },
|
|
246
221
|
]);
|
|
247
222
|
codes.push(`\n`);
|
|
248
223
|
}
|
|
249
224
|
function generateScriptSetupAndTemplate() {
|
|
250
|
-
if (!
|
|
225
|
+
if (!scriptSetup || !scriptSetupRanges) {
|
|
251
226
|
return;
|
|
252
227
|
}
|
|
253
228
|
const definePropMirrors = {};
|
|
254
229
|
let scriptSetupGeneratedOffset;
|
|
255
|
-
if (
|
|
230
|
+
if (scriptSetup.generic) {
|
|
256
231
|
if (!scriptRanges?.exportDefault) {
|
|
257
232
|
codes.push('export default ');
|
|
258
233
|
}
|
|
259
234
|
codes.push(`(<`);
|
|
260
235
|
codes.push([
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
236
|
+
scriptSetup.generic,
|
|
237
|
+
scriptSetup.name,
|
|
238
|
+
scriptSetup.genericOffset,
|
|
264
239
|
language_core_1.FileRangeCapabilities.full,
|
|
265
240
|
]);
|
|
266
|
-
if (!
|
|
241
|
+
if (!scriptSetup.generic.endsWith(',')) {
|
|
267
242
|
codes.push(`,`);
|
|
268
243
|
}
|
|
269
244
|
codes.push(`>`);
|
|
@@ -290,13 +265,13 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
290
265
|
for (const defineProp of scriptSetupRanges.defineProp) {
|
|
291
266
|
if (defineProp.defaultValue) {
|
|
292
267
|
if (defineProp.name) {
|
|
293
|
-
codes.push(
|
|
268
|
+
codes.push(scriptSetup.content.substring(defineProp.name.start, defineProp.name.end));
|
|
294
269
|
}
|
|
295
270
|
else {
|
|
296
271
|
codes.push('modelValue');
|
|
297
272
|
}
|
|
298
273
|
codes.push(`: `);
|
|
299
|
-
codes.push(
|
|
274
|
+
codes.push(scriptSetup.content.substring(defineProp.defaultValue.start, defineProp.defaultValue.end));
|
|
300
275
|
codes.push(`,\n`);
|
|
301
276
|
}
|
|
302
277
|
}
|
|
@@ -312,13 +287,13 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
312
287
|
for (const defineProp of scriptSetupRanges.defineProp) {
|
|
313
288
|
let propName = 'modelValue';
|
|
314
289
|
if (defineProp.name) {
|
|
315
|
-
propName =
|
|
290
|
+
propName = scriptSetup.content.substring(defineProp.name.start, defineProp.name.end);
|
|
316
291
|
const propMirrorStart = muggle.getLength(codes);
|
|
317
292
|
definePropMirrors[propName] = [propMirrorStart, propMirrorStart + propName.length];
|
|
318
293
|
}
|
|
319
294
|
codes.push(`${propName}${defineProp.required ? '' : '?'}: `);
|
|
320
295
|
if (defineProp.type) {
|
|
321
|
-
codes.push(
|
|
296
|
+
codes.push(scriptSetup.content.substring(defineProp.type.start, defineProp.type.end));
|
|
322
297
|
}
|
|
323
298
|
else if (defineProp.defaultValue) {
|
|
324
299
|
codes.push(`typeof __VLS_defaults['`);
|
|
@@ -347,7 +322,7 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
347
322
|
codes.push(`let __VLS_defaultProps!: `, `import('${vueCompilerOptions.lib}').VNodeProps`, `& import('${vueCompilerOptions.lib}').AllowedComponentProps`, `& import('${vueCompilerOptions.lib}').ComponentCustomProps`, `;\n`);
|
|
348
323
|
//#endregion
|
|
349
324
|
codes.push('return {} as {\n');
|
|
350
|
-
codes.push(`props: __VLS_Prettify<
|
|
325
|
+
codes.push(`props: __VLS_Prettify<__VLS_OmitKeepDiscriminatedUnion<typeof __VLS_fnPropsDefineComponent & typeof __VLS_fnPropsTypeOnly, keyof typeof __VLS_defaultProps>> & typeof __VLS_fnPropsSlots & typeof __VLS_defaultProps,\n`);
|
|
351
326
|
codes.push(`expose(exposed: import('${vueCompilerOptions.lib}').ShallowUnwrapRef<${scriptSetupRanges.expose.define ? 'typeof __VLS_exposed' : '{}'}>): void,\n`);
|
|
352
327
|
codes.push('attrs: any,\n');
|
|
353
328
|
codes.push('slots: ReturnType<typeof __VLS_template>,\n');
|
|
@@ -356,7 +331,7 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
356
331
|
codes.push('})(),\n');
|
|
357
332
|
codes.push(`) => ({} as import('${vueCompilerOptions.lib}').VNode & { __ctx?: Awaited<typeof __VLS_setup> }))`);
|
|
358
333
|
}
|
|
359
|
-
else if (!
|
|
334
|
+
else if (!script) {
|
|
360
335
|
// no script block, generate script setup code at root
|
|
361
336
|
scriptSetupGeneratedOffset = generateSetupFunction(false, 'export', definePropMirrors);
|
|
362
337
|
}
|
|
@@ -374,7 +349,7 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
374
349
|
if (!defineProp.name) {
|
|
375
350
|
continue;
|
|
376
351
|
}
|
|
377
|
-
const propName =
|
|
352
|
+
const propName = scriptSetup.content.substring(defineProp.name.start, defineProp.name.end);
|
|
378
353
|
const propMirror = definePropMirrors[propName];
|
|
379
354
|
if (propMirror) {
|
|
380
355
|
mirrorBehaviorMappings.push({
|
|
@@ -390,11 +365,11 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
390
365
|
}
|
|
391
366
|
}
|
|
392
367
|
function generateSetupFunction(functional, mode, definePropMirrors) {
|
|
393
|
-
if (!scriptSetupRanges || !
|
|
368
|
+
if (!scriptSetupRanges || !scriptSetup) {
|
|
394
369
|
return;
|
|
395
370
|
}
|
|
396
|
-
const definePropProposalA =
|
|
397
|
-
const definePropProposalB =
|
|
371
|
+
const definePropProposalA = scriptSetup.content.trimStart().startsWith('// @experimentalDefinePropProposal=kevinEdition') || vueCompilerOptions.experimentalDefinePropProposal === 'kevinEdition';
|
|
372
|
+
const definePropProposalB = scriptSetup.content.trimStart().startsWith('// @experimentalDefinePropProposal=johnsonEdition') || vueCompilerOptions.experimentalDefinePropProposal === 'johnsonEdition';
|
|
398
373
|
if (vueCompilerOptions.target >= 3.3) {
|
|
399
374
|
codes.push('const { ');
|
|
400
375
|
for (const macro of Object.keys(vueCompilerOptions.macros)) {
|
|
@@ -492,7 +467,7 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
492
467
|
addExtraReferenceVirtualCode('scriptSetup', defineProp.name.start, defineProp.name.end);
|
|
493
468
|
}
|
|
494
469
|
else if (defineProp.name) {
|
|
495
|
-
propName =
|
|
470
|
+
propName = scriptSetup.content.substring(defineProp.name.start, defineProp.name.end);
|
|
496
471
|
const start = muggle.getLength(codes);
|
|
497
472
|
definePropMirrors[propName] = [start, start + propName.length];
|
|
498
473
|
codes.push(propName);
|
|
@@ -506,7 +481,7 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
506
481
|
type = `NonNullable<typeof ${propName}['value']>`;
|
|
507
482
|
}
|
|
508
483
|
else if (defineProp.type) {
|
|
509
|
-
type =
|
|
484
|
+
type = scriptSetup.content.substring(defineProp.type.start, defineProp.type.end);
|
|
510
485
|
}
|
|
511
486
|
if (defineProp.required) {
|
|
512
487
|
codes.push(`{ required: true, type: import('${vueCompilerOptions.lib}').PropType<${type}> },\n`);
|
|
@@ -562,17 +537,20 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
562
537
|
}
|
|
563
538
|
function generateComponentOptions(functional) {
|
|
564
539
|
if (scriptSetupRanges && !bypassDefineComponent) {
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
}
|
|
572
|
-
|
|
540
|
+
const ranges = scriptSetupRanges;
|
|
541
|
+
const propsCodegens = [];
|
|
542
|
+
if (ranges.props.define?.arg) {
|
|
543
|
+
const arg = ranges.props.define.arg;
|
|
544
|
+
propsCodegens.push(() => {
|
|
545
|
+
addExtraReferenceVirtualCode('scriptSetup', arg.start, arg.end);
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
if (ranges.props.define?.typeArg) {
|
|
549
|
+
const typeArg = ranges.props.define.typeArg;
|
|
550
|
+
propsCodegens.push(() => {
|
|
573
551
|
usedHelperTypes.DefinePropsToOptions = true;
|
|
574
|
-
codes.push(
|
|
575
|
-
if (
|
|
552
|
+
codes.push(`{} as `);
|
|
553
|
+
if (ranges.props.withDefaults?.arg) {
|
|
576
554
|
usedHelperTypes.MergePropDefaults = true;
|
|
577
555
|
codes.push(`__VLS_WithDefaults<`);
|
|
578
556
|
}
|
|
@@ -581,22 +559,38 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
581
559
|
codes.push(`typeof __VLS_fnPropsTypeOnly`);
|
|
582
560
|
}
|
|
583
561
|
else {
|
|
584
|
-
addExtraReferenceVirtualCode('scriptSetup',
|
|
562
|
+
addExtraReferenceVirtualCode('scriptSetup', typeArg.start, typeArg.end);
|
|
585
563
|
}
|
|
586
564
|
codes.push(`>`);
|
|
587
|
-
if (
|
|
565
|
+
if (ranges.props.withDefaults?.arg) {
|
|
588
566
|
codes.push(`, typeof __VLS_withDefaultsArg`);
|
|
589
567
|
codes.push(`>`);
|
|
590
568
|
}
|
|
591
|
-
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
if (!functional && ranges.defineProp.length) {
|
|
572
|
+
propsCodegens.push(() => {
|
|
573
|
+
codes.push(`__VLS_propsOption_defineProp`);
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
if (propsCodegens.length === 1) {
|
|
577
|
+
codes.push(`props: `);
|
|
578
|
+
for (const generate of propsCodegens) {
|
|
579
|
+
generate();
|
|
592
580
|
}
|
|
593
|
-
|
|
594
|
-
|
|
581
|
+
codes.push(`,\n`);
|
|
582
|
+
}
|
|
583
|
+
else if (propsCodegens.length >= 2) {
|
|
584
|
+
codes.push(`props: {\n`);
|
|
585
|
+
for (const generate of propsCodegens) {
|
|
586
|
+
codes.push('...');
|
|
587
|
+
generate();
|
|
588
|
+
codes.push(',\n');
|
|
595
589
|
}
|
|
596
590
|
codes.push(`},\n`);
|
|
597
591
|
}
|
|
598
|
-
if (
|
|
599
|
-
codes.push(`emits: ({} as __VLS_NormalizeEmits<typeof `,
|
|
592
|
+
if (ranges.emits.define) {
|
|
593
|
+
codes.push(`emits: ({} as __VLS_NormalizeEmits<typeof `, ranges.emits.name ?? '__VLS_emit', `>),\n`);
|
|
600
594
|
}
|
|
601
595
|
}
|
|
602
596
|
if (scriptRanges?.exportDefault?.args) {
|
|
@@ -637,7 +631,7 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
637
631
|
}
|
|
638
632
|
}
|
|
639
633
|
function generateComponentForTemplateUsage(functional, cssIds) {
|
|
640
|
-
if (
|
|
634
|
+
if (scriptSetup && scriptSetupRanges) {
|
|
641
635
|
codes.push(`const __VLS_internalComponent = (await import('${vueCompilerOptions.lib}')).defineComponent({\n`);
|
|
642
636
|
generateComponentOptions(functional);
|
|
643
637
|
codes.push(`setup() {\n`);
|
|
@@ -646,9 +640,9 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
646
640
|
// bindings
|
|
647
641
|
const templateUsageVars = getTemplateUsageVars();
|
|
648
642
|
for (const [content, bindings] of [
|
|
649
|
-
[
|
|
650
|
-
scriptRanges &&
|
|
651
|
-
? [
|
|
643
|
+
[scriptSetup.content, scriptSetupRanges.bindings],
|
|
644
|
+
scriptRanges && script
|
|
645
|
+
? [script.content, scriptRanges.bindings]
|
|
652
646
|
: ['', []],
|
|
653
647
|
]) {
|
|
654
648
|
for (const expose of bindings) {
|
|
@@ -678,7 +672,7 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
678
672
|
codes.push(`},\n`); // setup() {
|
|
679
673
|
codes.push(`});\n`); // defineComponent({
|
|
680
674
|
}
|
|
681
|
-
else if (
|
|
675
|
+
else if (script) {
|
|
682
676
|
codes.push(`let __VLS_internalComponent!: typeof import('./${path_1.posix.basename(fileName)}')['default'];\n`);
|
|
683
677
|
}
|
|
684
678
|
else {
|
|
@@ -688,10 +682,10 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
688
682
|
function generateExportOptions() {
|
|
689
683
|
codes.push(`\n`);
|
|
690
684
|
codes.push(`const __VLS_componentsOption = `);
|
|
691
|
-
if (
|
|
685
|
+
if (script && scriptRanges?.exportDefault?.componentsOption) {
|
|
692
686
|
const componentsOption = scriptRanges.exportDefault.componentsOption;
|
|
693
687
|
codes.push([
|
|
694
|
-
|
|
688
|
+
script.content.substring(componentsOption.start, componentsOption.end),
|
|
695
689
|
'script',
|
|
696
690
|
componentsOption.start,
|
|
697
691
|
{
|
|
@@ -707,13 +701,13 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
707
701
|
}
|
|
708
702
|
function generateConstNameOption() {
|
|
709
703
|
codes.push(`\n`);
|
|
710
|
-
if (
|
|
704
|
+
if (script && scriptRanges?.exportDefault?.nameOption) {
|
|
711
705
|
const nameOption = scriptRanges.exportDefault.nameOption;
|
|
712
706
|
codes.push(`const __VLS_name = `);
|
|
713
|
-
codes.push(`${
|
|
707
|
+
codes.push(`${script.content.substring(nameOption.start, nameOption.end)} as const`);
|
|
714
708
|
codes.push(`;\n`);
|
|
715
709
|
}
|
|
716
|
-
else if (
|
|
710
|
+
else if (scriptSetup) {
|
|
717
711
|
codes.push(`let __VLS_name!: '${path_1.posix.basename(fileName.substring(0, fileName.lastIndexOf('.')))}';\n`);
|
|
718
712
|
}
|
|
719
713
|
else {
|
|
@@ -725,15 +719,15 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
725
719
|
codes.push(`let __VLS_ctx!: ${useGlobalThisTypeInCtx ? 'typeof globalThis &' : ''}`);
|
|
726
720
|
codes.push(`InstanceType<__VLS_PickNotAny<typeof __VLS_internalComponent, new () => {}>> & {\n`);
|
|
727
721
|
/* CSS Module */
|
|
728
|
-
for (let i = 0; i <
|
|
729
|
-
const style =
|
|
730
|
-
if (
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
722
|
+
for (let i = 0; i < styles.length; i++) {
|
|
723
|
+
const style = styles[i];
|
|
724
|
+
if (style.module) {
|
|
725
|
+
codes.push(`${style.module}: Record<string, string> & __VLS_Prettify<{}`);
|
|
726
|
+
for (const className of style.classNames) {
|
|
727
|
+
generateCssClassProperty(i, className.text.substring(1), { start: className.offset, end: className.offset + className.text.length }, 'string', false, true);
|
|
728
|
+
}
|
|
729
|
+
codes.push('>;\n');
|
|
735
730
|
}
|
|
736
|
-
codes.push('>;\n');
|
|
737
731
|
}
|
|
738
732
|
codes.push(`};\n`);
|
|
739
733
|
/* Components */
|
|
@@ -745,12 +739,13 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
745
739
|
/* Style Scoped */
|
|
746
740
|
codes.push('/* Style Scoped */\n');
|
|
747
741
|
codes.push('type __VLS_StyleScopedClasses = {}');
|
|
748
|
-
for (let i = 0; i <
|
|
749
|
-
const style =
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
742
|
+
for (let i = 0; i < styles.length; i++) {
|
|
743
|
+
const style = styles[i];
|
|
744
|
+
const option = vueCompilerOptions.experimentalResolveStyleCssClasses;
|
|
745
|
+
if ((option === 'always' || option === 'scoped') && style.scoped) {
|
|
746
|
+
for (const className of style.classNames) {
|
|
747
|
+
generateCssClassProperty(i, className.text.substring(1), { start: className.offset, end: className.offset + className.text.length }, 'boolean', true, !style.module);
|
|
748
|
+
}
|
|
754
749
|
}
|
|
755
750
|
}
|
|
756
751
|
codes.push(';\n');
|
|
@@ -813,7 +808,7 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
813
808
|
function generateCssVars() {
|
|
814
809
|
const emptyLocalVars = new Map();
|
|
815
810
|
const identifiers = new Set();
|
|
816
|
-
for (const style of
|
|
811
|
+
for (const style of styles) {
|
|
817
812
|
for (const cssBind of style.cssVars) {
|
|
818
813
|
(0, transform_1.walkInterpolationFragment)(ts, cssBind.text, ts.createSourceFile('/a.txt', cssBind.text, ts.ScriptTarget.ESNext), (frag, fragOffset, onlyForErrorMapping) => {
|
|
819
814
|
if (fragOffset === undefined) {
|
|
@@ -859,7 +854,7 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
859
854
|
function addVirtualCode(vueTag, start, end) {
|
|
860
855
|
muggle.offsetStack();
|
|
861
856
|
codes.push([
|
|
862
|
-
|
|
857
|
+
(vueTag === 'script' ? script : scriptSetup).content.substring(start, end),
|
|
863
858
|
vueTag,
|
|
864
859
|
start,
|
|
865
860
|
language_core_1.FileRangeCapabilities.full, // diagnostic also working for setup() returns unused in template checking
|
|
@@ -869,7 +864,7 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
869
864
|
function addExtraReferenceVirtualCode(vueTag, start, end) {
|
|
870
865
|
muggle.offsetStack();
|
|
871
866
|
codes.push([
|
|
872
|
-
|
|
867
|
+
(vueTag === 'script' ? script : scriptSetup).content.substring(start, end),
|
|
873
868
|
vueTag,
|
|
874
869
|
start,
|
|
875
870
|
{
|
|
@@ -5,7 +5,7 @@ import * as muggle from 'muggle-string';
|
|
|
5
5
|
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
6
6
|
import { Sfc, VueCompilerOptions } from '../types';
|
|
7
7
|
type Code = Segment<FileRangeCapabilities>;
|
|
8
|
-
export declare function generate(ts: typeof import('typescript/lib/tsserverlibrary'), compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions,
|
|
8
|
+
export declare function generate(ts: typeof import('typescript/lib/tsserverlibrary'), compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions, template: NonNullable<Sfc['template']>, shouldGenerateScopedClasses: boolean, stylesScopedClasses: Set<string>, hasScriptSetupSlots: boolean, slotsAssignName: string | undefined, propsAssignName: string | undefined, codegenStack: boolean): {
|
|
9
9
|
codes: Code[];
|
|
10
10
|
codeStacks: muggle.StackNode[];
|
|
11
11
|
formatCodes: Code[];
|