@vue/language-core 1.8.19 → 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 +111 -93
- package/out/generators/template.d.ts +1 -1
- package/out/generators/template.js +52 -58
- 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/plugins/vue-tsx.d.ts +9 -9
- package/out/plugins/vue-tsx.js +48 -28
- 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 +1 -1
- package/out/utils/transform.js +8 -8
- 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 +3 -3
- 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
|
@@ -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,6 +47,7 @@ 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: [],
|
|
@@ -64,8 +62,8 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
64
62
|
}
|
|
65
63
|
//#endregion
|
|
66
64
|
const bindingNames = new Set([
|
|
67
|
-
...scriptRanges?.bindings.map(range =>
|
|
68
|
-
...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)) ?? [],
|
|
69
67
|
]);
|
|
70
68
|
const bypassDefineComponent = lang === 'js' || lang === 'jsx';
|
|
71
69
|
const usedHelperTypes = {
|
|
@@ -85,12 +83,12 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
85
83
|
if (!generatedTemplate) {
|
|
86
84
|
generateTemplate(false);
|
|
87
85
|
}
|
|
88
|
-
if (
|
|
86
|
+
if (scriptSetup) {
|
|
89
87
|
// for code action edits
|
|
90
88
|
codes.push([
|
|
91
89
|
'',
|
|
92
90
|
'scriptSetup',
|
|
93
|
-
|
|
91
|
+
scriptSetup.content.length,
|
|
94
92
|
{},
|
|
95
93
|
]);
|
|
96
94
|
}
|
|
@@ -118,7 +116,7 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
118
116
|
};\n`);
|
|
119
117
|
}
|
|
120
118
|
if (usedHelperTypes.WithTemplateSlots) {
|
|
121
|
-
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`);
|
|
122
120
|
if (vueCompilerOptions.jsxSlots) {
|
|
123
121
|
usedHelperTypes.PropsChildren = true;
|
|
124
122
|
codes.push(`$props: __VLS_PropsChildren<S>;\n`);
|
|
@@ -130,9 +128,9 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
130
128
|
}
|
|
131
129
|
}
|
|
132
130
|
function generateSrc() {
|
|
133
|
-
if (!
|
|
131
|
+
if (!script?.src)
|
|
134
132
|
return;
|
|
135
|
-
let src =
|
|
133
|
+
let src = script.src;
|
|
136
134
|
if (src.endsWith('.d.ts'))
|
|
137
135
|
src = src.substring(0, src.length - '.d.ts'.length);
|
|
138
136
|
else if (src.endsWith('.ts'))
|
|
@@ -145,23 +143,23 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
145
143
|
codes.push([
|
|
146
144
|
`'${src}'`,
|
|
147
145
|
'script',
|
|
148
|
-
[
|
|
146
|
+
[script.srcOffset - 1, script.srcOffset + script.src.length + 1],
|
|
149
147
|
{
|
|
150
148
|
...language_core_1.FileRangeCapabilities.full,
|
|
151
|
-
rename: src ===
|
|
149
|
+
rename: src === script.src ? true : {
|
|
152
150
|
normalize: undefined,
|
|
153
151
|
apply(newName) {
|
|
154
152
|
if (newName.endsWith('.jsx')
|
|
155
153
|
|| newName.endsWith('.js')) {
|
|
156
154
|
newName = newName.split('.').slice(0, -1).join('.');
|
|
157
155
|
}
|
|
158
|
-
if (
|
|
156
|
+
if (script?.src?.endsWith('.d.ts')) {
|
|
159
157
|
newName = newName + '.d.ts';
|
|
160
158
|
}
|
|
161
|
-
else if (
|
|
159
|
+
else if (script?.src?.endsWith('.ts')) {
|
|
162
160
|
newName = newName + '.ts';
|
|
163
161
|
}
|
|
164
|
-
else if (
|
|
162
|
+
else if (script?.src?.endsWith('.tsx')) {
|
|
165
163
|
newName = newName + '.tsx';
|
|
166
164
|
}
|
|
167
165
|
return newName;
|
|
@@ -173,15 +171,15 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
173
171
|
codes.push(`export { default } from '${src}';\n`);
|
|
174
172
|
}
|
|
175
173
|
function generateScriptContentBeforeExportDefault() {
|
|
176
|
-
if (!
|
|
174
|
+
if (!script)
|
|
177
175
|
return;
|
|
178
|
-
if (!!
|
|
176
|
+
if (!!scriptSetup && scriptRanges?.exportDefault) {
|
|
179
177
|
addVirtualCode('script', 0, scriptRanges.exportDefault.expression.start);
|
|
180
178
|
}
|
|
181
179
|
else {
|
|
182
180
|
let isExportRawObject = false;
|
|
183
181
|
if (scriptRanges?.exportDefault) {
|
|
184
|
-
isExportRawObject =
|
|
182
|
+
isExportRawObject = script.content.substring(scriptRanges.exportDefault.expression.start, scriptRanges.exportDefault.expression.end).startsWith('{');
|
|
185
183
|
}
|
|
186
184
|
if (isExportRawObject && vueCompilerOptions.optionsWrapper.length === 2 && scriptRanges?.exportDefault) {
|
|
187
185
|
addVirtualCode('script', 0, scriptRanges.exportDefault.expression.start);
|
|
@@ -207,63 +205,63 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
207
205
|
}]);
|
|
208
206
|
}
|
|
209
207
|
codes.push(vueCompilerOptions.optionsWrapper[1]);
|
|
210
|
-
addVirtualCode('script', scriptRanges.exportDefault.expression.end,
|
|
208
|
+
addVirtualCode('script', scriptRanges.exportDefault.expression.end, script.content.length);
|
|
211
209
|
}
|
|
212
210
|
else {
|
|
213
|
-
addVirtualCode('script', 0,
|
|
211
|
+
addVirtualCode('script', 0, script.content.length);
|
|
214
212
|
}
|
|
215
213
|
}
|
|
216
214
|
}
|
|
217
215
|
function generateScriptContentAfterExportDefault() {
|
|
218
|
-
if (!
|
|
216
|
+
if (!script)
|
|
219
217
|
return;
|
|
220
|
-
if (!!
|
|
221
|
-
addVirtualCode('script', scriptRanges.exportDefault.end,
|
|
218
|
+
if (!!scriptSetup && scriptRanges?.exportDefault) {
|
|
219
|
+
addVirtualCode('script', scriptRanges.exportDefault.end, script.content.length);
|
|
222
220
|
}
|
|
223
221
|
}
|
|
224
222
|
function generateScriptSetupImports() {
|
|
225
|
-
if (!
|
|
223
|
+
if (!scriptSetup)
|
|
226
224
|
return;
|
|
227
225
|
if (!scriptSetupRanges)
|
|
228
226
|
return;
|
|
229
227
|
codes.push([
|
|
230
|
-
|
|
228
|
+
scriptSetup.content.substring(0, Math.max(scriptSetupRanges.importSectionEndOffset, scriptSetupRanges.leadingCommentEndOffset)) + '\n',
|
|
231
229
|
'scriptSetup',
|
|
232
230
|
0,
|
|
233
231
|
language_core_1.FileRangeCapabilities.full,
|
|
234
232
|
]);
|
|
235
233
|
}
|
|
236
234
|
function generateExportDefaultEndMapping() {
|
|
237
|
-
if (!
|
|
235
|
+
if (!scriptSetup) {
|
|
238
236
|
return;
|
|
239
237
|
}
|
|
240
238
|
// fix https://github.com/vuejs/language-tools/issues/1127
|
|
241
239
|
codes.push([
|
|
242
240
|
'',
|
|
243
241
|
'scriptSetup',
|
|
244
|
-
|
|
242
|
+
scriptSetup.content.length,
|
|
245
243
|
{ diagnostic: true },
|
|
246
244
|
]);
|
|
247
245
|
codes.push(`\n`);
|
|
248
246
|
}
|
|
249
247
|
function generateScriptSetupAndTemplate() {
|
|
250
|
-
if (!
|
|
248
|
+
if (!scriptSetup || !scriptSetupRanges) {
|
|
251
249
|
return;
|
|
252
250
|
}
|
|
253
251
|
const definePropMirrors = {};
|
|
254
252
|
let scriptSetupGeneratedOffset;
|
|
255
|
-
if (
|
|
253
|
+
if (scriptSetup.generic) {
|
|
256
254
|
if (!scriptRanges?.exportDefault) {
|
|
257
255
|
codes.push('export default ');
|
|
258
256
|
}
|
|
259
257
|
codes.push(`(<`);
|
|
260
258
|
codes.push([
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
259
|
+
scriptSetup.generic,
|
|
260
|
+
scriptSetup.name,
|
|
261
|
+
scriptSetup.genericOffset,
|
|
264
262
|
language_core_1.FileRangeCapabilities.full,
|
|
265
263
|
]);
|
|
266
|
-
if (!
|
|
264
|
+
if (!scriptSetup.generic.endsWith(',')) {
|
|
267
265
|
codes.push(`,`);
|
|
268
266
|
}
|
|
269
267
|
codes.push(`>`);
|
|
@@ -290,13 +288,13 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
290
288
|
for (const defineProp of scriptSetupRanges.defineProp) {
|
|
291
289
|
if (defineProp.defaultValue) {
|
|
292
290
|
if (defineProp.name) {
|
|
293
|
-
codes.push(
|
|
291
|
+
codes.push(scriptSetup.content.substring(defineProp.name.start, defineProp.name.end));
|
|
294
292
|
}
|
|
295
293
|
else {
|
|
296
294
|
codes.push('modelValue');
|
|
297
295
|
}
|
|
298
296
|
codes.push(`: `);
|
|
299
|
-
codes.push(
|
|
297
|
+
codes.push(scriptSetup.content.substring(defineProp.defaultValue.start, defineProp.defaultValue.end));
|
|
300
298
|
codes.push(`,\n`);
|
|
301
299
|
}
|
|
302
300
|
}
|
|
@@ -312,13 +310,13 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
312
310
|
for (const defineProp of scriptSetupRanges.defineProp) {
|
|
313
311
|
let propName = 'modelValue';
|
|
314
312
|
if (defineProp.name) {
|
|
315
|
-
propName =
|
|
313
|
+
propName = scriptSetup.content.substring(defineProp.name.start, defineProp.name.end);
|
|
316
314
|
const propMirrorStart = muggle.getLength(codes);
|
|
317
315
|
definePropMirrors[propName] = [propMirrorStart, propMirrorStart + propName.length];
|
|
318
316
|
}
|
|
319
317
|
codes.push(`${propName}${defineProp.required ? '' : '?'}: `);
|
|
320
318
|
if (defineProp.type) {
|
|
321
|
-
codes.push(
|
|
319
|
+
codes.push(scriptSetup.content.substring(defineProp.type.start, defineProp.type.end));
|
|
322
320
|
}
|
|
323
321
|
else if (defineProp.defaultValue) {
|
|
324
322
|
codes.push(`typeof __VLS_defaults['`);
|
|
@@ -347,7 +345,7 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
347
345
|
codes.push(`let __VLS_defaultProps!: `, `import('${vueCompilerOptions.lib}').VNodeProps`, `& import('${vueCompilerOptions.lib}').AllowedComponentProps`, `& import('${vueCompilerOptions.lib}').ComponentCustomProps`, `;\n`);
|
|
348
346
|
//#endregion
|
|
349
347
|
codes.push('return {} as {\n');
|
|
350
|
-
codes.push(`props: __VLS_Prettify<
|
|
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`);
|
|
351
349
|
codes.push(`expose(exposed: import('${vueCompilerOptions.lib}').ShallowUnwrapRef<${scriptSetupRanges.expose.define ? 'typeof __VLS_exposed' : '{}'}>): void,\n`);
|
|
352
350
|
codes.push('attrs: any,\n');
|
|
353
351
|
codes.push('slots: ReturnType<typeof __VLS_template>,\n');
|
|
@@ -356,7 +354,7 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
356
354
|
codes.push('})(),\n');
|
|
357
355
|
codes.push(`) => ({} as import('${vueCompilerOptions.lib}').VNode & { __ctx?: Awaited<typeof __VLS_setup> }))`);
|
|
358
356
|
}
|
|
359
|
-
else if (!
|
|
357
|
+
else if (!script) {
|
|
360
358
|
// no script block, generate script setup code at root
|
|
361
359
|
scriptSetupGeneratedOffset = generateSetupFunction(false, 'export', definePropMirrors);
|
|
362
360
|
}
|
|
@@ -374,7 +372,7 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
374
372
|
if (!defineProp.name) {
|
|
375
373
|
continue;
|
|
376
374
|
}
|
|
377
|
-
const propName =
|
|
375
|
+
const propName = scriptSetup.content.substring(defineProp.name.start, defineProp.name.end);
|
|
378
376
|
const propMirror = definePropMirrors[propName];
|
|
379
377
|
if (propMirror) {
|
|
380
378
|
mirrorBehaviorMappings.push({
|
|
@@ -390,11 +388,11 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
390
388
|
}
|
|
391
389
|
}
|
|
392
390
|
function generateSetupFunction(functional, mode, definePropMirrors) {
|
|
393
|
-
if (!scriptSetupRanges || !
|
|
391
|
+
if (!scriptSetupRanges || !scriptSetup) {
|
|
394
392
|
return;
|
|
395
393
|
}
|
|
396
|
-
const definePropProposalA =
|
|
397
|
-
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';
|
|
398
396
|
if (vueCompilerOptions.target >= 3.3) {
|
|
399
397
|
codes.push('const { ');
|
|
400
398
|
for (const macro of Object.keys(vueCompilerOptions.macros)) {
|
|
@@ -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`);
|
|
@@ -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) {
|
|
@@ -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,15 +742,15 @@ 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 */
|
|
@@ -745,12 +762,13 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
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');
|
|
@@ -813,7 +831,7 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
813
831
|
function generateCssVars() {
|
|
814
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) {
|
|
@@ -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
|
{
|
|
@@ -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[];
|