@vue/language-core 1.8.18 → 1.8.19
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.js +63 -63
- package/out/generators/template.d.ts +1 -1
- package/out/generators/template.js +10 -11
- 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 +29 -16
- package/out/plugins/vue-tsx.js +15 -15
- package/out/utils/transform.d.ts +1 -1
- package/out/utils/transform.js +6 -6
- package/package.json +4 -4
package/out/generators/script.js
CHANGED
|
@@ -53,22 +53,13 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
53
53
|
};
|
|
54
54
|
scriptSetupRanges = {
|
|
55
55
|
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,
|
|
56
|
+
props: {},
|
|
57
|
+
emits: {},
|
|
58
|
+
expose: {},
|
|
59
|
+
slots: {},
|
|
71
60
|
defineProp: [],
|
|
61
|
+
importSectionEndOffset: 0,
|
|
62
|
+
leadingCommentEndOffset: 0,
|
|
72
63
|
};
|
|
73
64
|
}
|
|
74
65
|
//#endregion
|
|
@@ -285,13 +276,13 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
285
276
|
//#region props
|
|
286
277
|
codes.push(`const __VLS_fnComponent = `);
|
|
287
278
|
codes.push(`(await import('${vueCompilerOptions.lib}')).defineComponent({\n`);
|
|
288
|
-
if (scriptSetupRanges.
|
|
279
|
+
if (scriptSetupRanges.props.define?.arg) {
|
|
289
280
|
codes.push(`props: `);
|
|
290
|
-
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.
|
|
281
|
+
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.props.define.arg.start, scriptSetupRanges.props.define.arg.end);
|
|
291
282
|
codes.push(`,\n`);
|
|
292
283
|
}
|
|
293
|
-
if (scriptSetupRanges.
|
|
294
|
-
codes.push(`emits: ({} as __VLS_NormalizeEmits<typeof `, scriptSetupRanges.
|
|
284
|
+
if (scriptSetupRanges.emits.define) {
|
|
285
|
+
codes.push(`emits: ({} as __VLS_NormalizeEmits<typeof `, scriptSetupRanges.emits.name ?? '__VLS_emit', `>),\n`);
|
|
295
286
|
}
|
|
296
287
|
codes.push(`});\n`);
|
|
297
288
|
if (scriptSetupRanges.defineProp.length) {
|
|
@@ -312,9 +303,9 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
312
303
|
codes.push(`};\n`);
|
|
313
304
|
}
|
|
314
305
|
codes.push(`let __VLS_fnPropsTypeOnly!: {}`); // TODO: reuse __VLS_fnPropsTypeOnly even without generic, and remove __VLS_propsOption_defineProp
|
|
315
|
-
if (scriptSetupRanges.
|
|
306
|
+
if (scriptSetupRanges.props.define?.typeArg) {
|
|
316
307
|
codes.push(` & `);
|
|
317
|
-
addVirtualCode('scriptSetup', scriptSetupRanges.
|
|
308
|
+
addVirtualCode('scriptSetup', scriptSetupRanges.props.define.typeArg.start, scriptSetupRanges.props.define.typeArg.end);
|
|
318
309
|
}
|
|
319
310
|
if (scriptSetupRanges.defineProp.length) {
|
|
320
311
|
codes.push(` & {\n`);
|
|
@@ -345,7 +336,7 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
345
336
|
codes.push(`let __VLS_fnPropsDefineComponent!: InstanceType<typeof __VLS_fnComponent>['$props']`);
|
|
346
337
|
codes.push(`;\n`);
|
|
347
338
|
codes.push(`let __VLS_fnPropsSlots!: `);
|
|
348
|
-
if (scriptSetupRanges.
|
|
339
|
+
if (scriptSetupRanges.slots.define && vueCompilerOptions.jsxSlots) {
|
|
349
340
|
usedHelperTypes.PropsChildren = true;
|
|
350
341
|
codes.push(`__VLS_PropsChildren<typeof __VLS_slots>`);
|
|
351
342
|
}
|
|
@@ -357,10 +348,10 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
357
348
|
//#endregion
|
|
358
349
|
codes.push('return {} as {\n');
|
|
359
350
|
codes.push(`props: __VLS_Prettify<Omit<typeof __VLS_fnPropsDefineComponent & typeof __VLS_fnPropsTypeOnly, keyof typeof __VLS_defaultProps>> & typeof __VLS_fnPropsSlots & typeof __VLS_defaultProps,\n`);
|
|
360
|
-
codes.push(`expose(exposed: import('${vueCompilerOptions.lib}').ShallowUnwrapRef<${scriptSetupRanges.
|
|
351
|
+
codes.push(`expose(exposed: import('${vueCompilerOptions.lib}').ShallowUnwrapRef<${scriptSetupRanges.expose.define ? 'typeof __VLS_exposed' : '{}'}>): void,\n`);
|
|
361
352
|
codes.push('attrs: any,\n');
|
|
362
353
|
codes.push('slots: ReturnType<typeof __VLS_template>,\n');
|
|
363
|
-
codes.push(`emit: typeof ${scriptSetupRanges.
|
|
354
|
+
codes.push(`emit: typeof ${scriptSetupRanges.emits.name ?? '__VLS_emit'},\n`);
|
|
364
355
|
codes.push('};\n');
|
|
365
356
|
codes.push('})(),\n');
|
|
366
357
|
codes.push(`) => ({} as import('${vueCompilerOptions.lib}').VNode & { __ctx?: Awaited<typeof __VLS_setup> }))`);
|
|
@@ -429,35 +420,44 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
429
420
|
}
|
|
430
421
|
const scriptSetupGeneratedOffset = muggle.getLength(codes) - scriptSetupRanges.importSectionEndOffset;
|
|
431
422
|
let setupCodeModifies = [];
|
|
432
|
-
if (scriptSetupRanges.
|
|
433
|
-
const
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
423
|
+
if (scriptSetupRanges.props.define && !scriptSetupRanges.props.name) {
|
|
424
|
+
const range = scriptSetupRanges.props.withDefaults ?? scriptSetupRanges.props.define;
|
|
425
|
+
const statement = scriptSetupRanges.props.define.statement;
|
|
426
|
+
if (statement.start === range.start && statement.end === range.end) {
|
|
427
|
+
setupCodeModifies.push([() => codes.push(`const __VLS_props = `), range.start, range.start]);
|
|
428
|
+
}
|
|
429
|
+
else {
|
|
430
|
+
setupCodeModifies.push([() => {
|
|
431
|
+
codes.push(`const __VLS_props = `);
|
|
432
|
+
addVirtualCode('scriptSetup', range.start, range.end);
|
|
433
|
+
codes.push(`;\n`);
|
|
434
|
+
addVirtualCode('scriptSetup', statement.start, range.start);
|
|
435
|
+
codes.push(`__VLS_props`);
|
|
436
|
+
}, statement.start, range.end]);
|
|
437
|
+
}
|
|
438
438
|
}
|
|
439
|
-
if (scriptSetupRanges.
|
|
440
|
-
setupCodeModifies.push([() => codes.push(`const __VLS_slots = `), scriptSetupRanges.
|
|
439
|
+
if (scriptSetupRanges.slots.define && !scriptSetupRanges.slots.name) {
|
|
440
|
+
setupCodeModifies.push([() => codes.push(`const __VLS_slots = `), scriptSetupRanges.slots.define.start, scriptSetupRanges.slots.define.start]);
|
|
441
441
|
}
|
|
442
|
-
if (scriptSetupRanges.
|
|
443
|
-
setupCodeModifies.push([() => codes.push(`const __VLS_emit = `), scriptSetupRanges.
|
|
442
|
+
if (scriptSetupRanges.emits.define && !scriptSetupRanges.emits.name) {
|
|
443
|
+
setupCodeModifies.push([() => codes.push(`const __VLS_emit = `), scriptSetupRanges.emits.define.start, scriptSetupRanges.emits.define.start]);
|
|
444
444
|
}
|
|
445
|
-
if (scriptSetupRanges.
|
|
445
|
+
if (scriptSetupRanges.expose.define) {
|
|
446
446
|
setupCodeModifies.push([() => {
|
|
447
|
-
if (scriptSetupRanges?.
|
|
447
|
+
if (scriptSetupRanges?.expose.define?.typeArg) {
|
|
448
448
|
codes.push(`let __VLS_exposed!: `);
|
|
449
|
-
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.
|
|
449
|
+
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.expose.define.typeArg.start, scriptSetupRanges.expose.define.typeArg.end);
|
|
450
450
|
codes.push(`;\n`);
|
|
451
451
|
}
|
|
452
|
-
else if (scriptSetupRanges?.
|
|
452
|
+
else if (scriptSetupRanges?.expose.define?.arg) {
|
|
453
453
|
codes.push(`const __VLS_exposed = `);
|
|
454
|
-
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.
|
|
454
|
+
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.expose.define.arg.start, scriptSetupRanges.expose.define.arg.end);
|
|
455
455
|
codes.push(`;\n`);
|
|
456
456
|
}
|
|
457
457
|
else {
|
|
458
458
|
codes.push(`const __VLS_exposed = {};\n`);
|
|
459
459
|
}
|
|
460
|
-
}, scriptSetupRanges.
|
|
460
|
+
}, scriptSetupRanges.expose.define.start, scriptSetupRanges.expose.define.start]);
|
|
461
461
|
}
|
|
462
462
|
setupCodeModifies = setupCodeModifies.sort((a, b) => a[1] - b[1]);
|
|
463
463
|
if (setupCodeModifies.length) {
|
|
@@ -477,10 +477,10 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
477
477
|
else {
|
|
478
478
|
addVirtualCode('scriptSetup', scriptSetupRanges.importSectionEndOffset);
|
|
479
479
|
}
|
|
480
|
-
if (scriptSetupRanges.
|
|
480
|
+
if (scriptSetupRanges.props.define?.typeArg && scriptSetupRanges.props.withDefaults?.arg) {
|
|
481
481
|
// fix https://github.com/vuejs/language-tools/issues/1187
|
|
482
482
|
codes.push(`const __VLS_withDefaultsArg = (function <T>(t: T) { return t })(`);
|
|
483
|
-
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.
|
|
483
|
+
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.props.withDefaults.arg.start, scriptSetupRanges.props.withDefaults.arg.end);
|
|
484
484
|
codes.push(`);\n`);
|
|
485
485
|
}
|
|
486
486
|
if (!functional && scriptSetupRanges.defineProp.length) {
|
|
@@ -519,7 +519,7 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
519
519
|
}
|
|
520
520
|
generateTemplate(functional);
|
|
521
521
|
if (mode === 'return' || mode === 'export') {
|
|
522
|
-
if (!vueCompilerOptions.skipTemplateCodegen && (htmlGen?.hasSlot || scriptSetupRanges?.
|
|
522
|
+
if (!vueCompilerOptions.skipTemplateCodegen && (htmlGen?.hasSlot || scriptSetupRanges?.slots.define)) {
|
|
523
523
|
usedHelperTypes.WithTemplateSlots = true;
|
|
524
524
|
codes.push(`const __VLS_component = `);
|
|
525
525
|
generateComponent(functional);
|
|
@@ -553,7 +553,7 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
553
553
|
codes.push(`setup() {\n`);
|
|
554
554
|
codes.push(`return {\n`);
|
|
555
555
|
generateSetupReturns();
|
|
556
|
-
if (scriptSetupRanges.
|
|
556
|
+
if (scriptSetupRanges.expose.define) {
|
|
557
557
|
codes.push(`...__VLS_exposed,\n`);
|
|
558
558
|
}
|
|
559
559
|
codes.push(`};\n`);
|
|
@@ -562,17 +562,17 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
562
562
|
}
|
|
563
563
|
function generateComponentOptions(functional) {
|
|
564
564
|
if (scriptSetupRanges && !bypassDefineComponent) {
|
|
565
|
-
if (scriptSetupRanges.
|
|
565
|
+
if (scriptSetupRanges.props.define?.arg || scriptSetupRanges.props.define?.typeArg || (!functional && scriptSetupRanges.defineProp.length)) {
|
|
566
566
|
codes.push(`props: {\n`);
|
|
567
|
-
if (scriptSetupRanges.
|
|
567
|
+
if (scriptSetupRanges.props.define?.arg) {
|
|
568
568
|
codes.push('...');
|
|
569
|
-
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.
|
|
569
|
+
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.props.define.arg.start, scriptSetupRanges.props.define.arg.end);
|
|
570
570
|
codes.push(',\n');
|
|
571
571
|
}
|
|
572
|
-
if (scriptSetupRanges.
|
|
572
|
+
if (scriptSetupRanges.props.define?.typeArg) {
|
|
573
573
|
usedHelperTypes.DefinePropsToOptions = true;
|
|
574
574
|
codes.push('...{} as ');
|
|
575
|
-
if (scriptSetupRanges.
|
|
575
|
+
if (scriptSetupRanges.props.withDefaults?.arg) {
|
|
576
576
|
usedHelperTypes.MergePropDefaults = true;
|
|
577
577
|
codes.push(`__VLS_WithDefaults<`);
|
|
578
578
|
}
|
|
@@ -581,10 +581,10 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
581
581
|
codes.push(`typeof __VLS_fnPropsTypeOnly`);
|
|
582
582
|
}
|
|
583
583
|
else {
|
|
584
|
-
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.
|
|
584
|
+
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.props.define.typeArg.start, scriptSetupRanges.props.define.typeArg.end);
|
|
585
585
|
}
|
|
586
586
|
codes.push(`>`);
|
|
587
|
-
if (scriptSetupRanges.
|
|
587
|
+
if (scriptSetupRanges.props.withDefaults?.arg) {
|
|
588
588
|
codes.push(`, typeof __VLS_withDefaultsArg`);
|
|
589
589
|
codes.push(`>`);
|
|
590
590
|
}
|
|
@@ -595,8 +595,8 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
595
595
|
}
|
|
596
596
|
codes.push(`},\n`);
|
|
597
597
|
}
|
|
598
|
-
if (scriptSetupRanges.
|
|
599
|
-
codes.push(`emits: ({} as __VLS_NormalizeEmits<typeof `, scriptSetupRanges.
|
|
598
|
+
if (scriptSetupRanges.emits.define) {
|
|
599
|
+
codes.push(`emits: ({} as __VLS_NormalizeEmits<typeof `, scriptSetupRanges.emits.name ?? '__VLS_emit', `>),\n`);
|
|
600
600
|
}
|
|
601
601
|
}
|
|
602
602
|
if (scriptRanges?.exportDefault?.args) {
|
|
@@ -606,14 +606,14 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
606
606
|
function generateSetupReturns() {
|
|
607
607
|
if (scriptSetupRanges && bypassDefineComponent) {
|
|
608
608
|
// fill $props
|
|
609
|
-
if (scriptSetupRanges.
|
|
609
|
+
if (scriptSetupRanges.props.define) {
|
|
610
610
|
// NOTE: defineProps is inaccurate for $props
|
|
611
|
-
codes.push(`$props: __VLS_makeOptional(${scriptSetupRanges.
|
|
612
|
-
codes.push(`...${scriptSetupRanges.
|
|
611
|
+
codes.push(`$props: __VLS_makeOptional(${scriptSetupRanges.props.name ?? `__VLS_props`}),\n`);
|
|
612
|
+
codes.push(`...${scriptSetupRanges.props.name ?? `__VLS_props`},\n`);
|
|
613
613
|
}
|
|
614
614
|
// fill $emit
|
|
615
|
-
if (scriptSetupRanges.
|
|
616
|
-
codes.push(`$emit: ${scriptSetupRanges.
|
|
615
|
+
if (scriptSetupRanges.emits.define) {
|
|
616
|
+
codes.push(`$emit: ${scriptSetupRanges.emits.name ?? '__VLS_emit'},\n`);
|
|
617
617
|
}
|
|
618
618
|
}
|
|
619
619
|
}
|
|
@@ -739,7 +739,7 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
739
739
|
/* Components */
|
|
740
740
|
codes.push('/* Components */\n');
|
|
741
741
|
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?.
|
|
742
|
+
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
743
|
codes.push(`let __VLS_localComponents!: typeof __VLS_otherComponents & Omit<typeof __VLS_own, keyof typeof __VLS_otherComponents>;\n`);
|
|
744
744
|
codes.push(`let __VLS_components!: typeof __VLS_localComponents & __VLS_GlobalComponents & typeof __VLS_ctx;\n`); // for html completion, TS references...
|
|
745
745
|
/* Style Scoped */
|
|
@@ -770,11 +770,11 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
770
770
|
}
|
|
771
771
|
if (!htmlGen) {
|
|
772
772
|
codes.push(`// no template\n`);
|
|
773
|
-
if (!scriptSetupRanges?.
|
|
773
|
+
if (!scriptSetupRanges?.slots.define) {
|
|
774
774
|
codes.push(`const __VLS_slots = {};\n`);
|
|
775
775
|
}
|
|
776
776
|
}
|
|
777
|
-
codes.push(`return ${scriptSetupRanges?.
|
|
777
|
+
codes.push(`return ${scriptSetupRanges?.slots.name ?? '__VLS_slots'};\n`);
|
|
778
778
|
return { cssIds };
|
|
779
779
|
function generateCssClassProperty(styleIndex, className, classRange, propertyType, optional, referencesCodeLens) {
|
|
780
780
|
codes.push(`\n & { `);
|
|
@@ -811,7 +811,7 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
811
811
|
codes.push(` }`);
|
|
812
812
|
}
|
|
813
813
|
function generateCssVars() {
|
|
814
|
-
const emptyLocalVars =
|
|
814
|
+
const emptyLocalVars = new Map();
|
|
815
815
|
const identifiers = new Set();
|
|
816
816
|
for (const style of _sfc.styles) {
|
|
817
817
|
for (const cssBind of style.cssVars) {
|
|
@@ -850,7 +850,7 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
|
|
|
850
850
|
usageVars.add(tag.split('.')[0]);
|
|
851
851
|
}
|
|
852
852
|
}
|
|
853
|
-
for (const _id of htmlGen.
|
|
853
|
+
for (const _id of htmlGen.accessedGlobalVariables) {
|
|
854
854
|
usageVars.add(_id);
|
|
855
855
|
}
|
|
856
856
|
}
|
|
@@ -13,7 +13,7 @@ export declare function generate(ts: typeof import('typescript/lib/tsserverlibra
|
|
|
13
13
|
cssCodes: Code[];
|
|
14
14
|
cssCodeStacks: muggle.StackNode[];
|
|
15
15
|
tagNames: Record<string, number[]>;
|
|
16
|
-
|
|
16
|
+
accessedGlobalVariables: Set<string>;
|
|
17
17
|
hasSlot: boolean;
|
|
18
18
|
};
|
|
19
19
|
export declare function walkElementNodes(node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode, cb: (node: CompilerDOM.ElementNode) => void): void;
|
|
@@ -92,9 +92,9 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
|
|
|
92
92
|
const slots = new Map();
|
|
93
93
|
const slotExps = new Map();
|
|
94
94
|
const tagNames = collectTagOffsets();
|
|
95
|
-
const localVars =
|
|
95
|
+
const localVars = new Map();
|
|
96
96
|
const tempVars = [];
|
|
97
|
-
const
|
|
97
|
+
const accessedGlobalVariables = new Set();
|
|
98
98
|
const scopedClasses = [];
|
|
99
99
|
const blockConditions = [];
|
|
100
100
|
const hasSlotElements = new Set();
|
|
@@ -105,7 +105,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
|
|
|
105
105
|
let expectedErrorStart;
|
|
106
106
|
let expectedErrorNode;
|
|
107
107
|
if (propsAssignName) {
|
|
108
|
-
localVars
|
|
108
|
+
localVars.set(propsAssignName, 1);
|
|
109
109
|
}
|
|
110
110
|
generatePreResolveComponents();
|
|
111
111
|
if (sfc.templateAst) {
|
|
@@ -124,7 +124,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
|
|
|
124
124
|
cssCodes,
|
|
125
125
|
cssCodeStacks,
|
|
126
126
|
tagNames,
|
|
127
|
-
|
|
127
|
+
accessedGlobalVariables,
|
|
128
128
|
hasSlot,
|
|
129
129
|
};
|
|
130
130
|
function createSlotsTypeCode() {
|
|
@@ -458,7 +458,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
|
|
|
458
458
|
const collectAst = createTsAst(node.parseResult, `const [${leftExpressionText}]`);
|
|
459
459
|
(0, transform_1.colletVars)(ts, collectAst, forBlockVars);
|
|
460
460
|
for (const varName of forBlockVars)
|
|
461
|
-
localVars
|
|
461
|
+
localVars.set(varName, (localVars.get(varName) ?? 0) + 1);
|
|
462
462
|
codes.push([leftExpressionText, 'template', leftExpressionRange.start, capabilitiesPresets.all]);
|
|
463
463
|
formatCodes.push(...createFormatCode(leftExpressionText, leftExpressionRange.start, formatBrackets.normal));
|
|
464
464
|
}
|
|
@@ -477,7 +477,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
|
|
|
477
477
|
formatCodes.push(...createFormatCode(source.content, source.loc.start.offset, formatBrackets.normal));
|
|
478
478
|
}
|
|
479
479
|
for (const varName of forBlockVars)
|
|
480
|
-
localVars
|
|
480
|
+
localVars.set(varName, localVars.get(varName) - 1);
|
|
481
481
|
}
|
|
482
482
|
function visitElementNode(node, parentEl, componentCtxVar) {
|
|
483
483
|
codes.push(`{\n`);
|
|
@@ -698,8 +698,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
|
|
|
698
698
|
}
|
|
699
699
|
codes.push(';\n');
|
|
700
700
|
slotBlockVars.forEach(varName => {
|
|
701
|
-
localVars
|
|
702
|
-
localVars[varName]++;
|
|
701
|
+
localVars.set(varName, (localVars.get(varName) ?? 0) + 1);
|
|
703
702
|
});
|
|
704
703
|
let prev;
|
|
705
704
|
for (const childNode of node.children) {
|
|
@@ -708,7 +707,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
|
|
|
708
707
|
}
|
|
709
708
|
resolveComment();
|
|
710
709
|
slotBlockVars.forEach(varName => {
|
|
711
|
-
localVars
|
|
710
|
+
localVars.set(varName, localVars.get(varName) - 1);
|
|
712
711
|
});
|
|
713
712
|
let isStatic = true;
|
|
714
713
|
if (slotDir?.arg?.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */) {
|
|
@@ -1092,7 +1091,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
|
|
|
1092
1091
|
&& prop.name !== 'model'
|
|
1093
1092
|
&& prop.name !== 'bind'
|
|
1094
1093
|
&& (prop.name !== 'scope' && prop.name !== 'data')) {
|
|
1095
|
-
|
|
1094
|
+
accessedGlobalVariables.add((0, shared_1.camelize)('v-' + prop.name));
|
|
1096
1095
|
if (prop.arg?.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */ && !prop.arg.isStatic) {
|
|
1097
1096
|
codes.push(...createInterpolationCode(prop.arg.content, prop.arg.loc, prop.arg.loc.start.offset + prop.arg.loc.source.indexOf(prop.arg.content), capabilitiesPresets.all, '(', ')'), ';\n');
|
|
1098
1097
|
formatCodes.push(...createFormatCode(prop.arg.content, prop.arg.loc.start.offset, formatBrackets.normal));
|
|
@@ -1342,7 +1341,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
|
|
|
1342
1341
|
}
|
|
1343
1342
|
codes.push(addSuffix);
|
|
1344
1343
|
}
|
|
1345
|
-
}, localVars,
|
|
1344
|
+
}, localVars, accessedGlobalVariables, vueCompilerOptions);
|
|
1346
1345
|
if (start !== undefined) {
|
|
1347
1346
|
for (const v of vars) {
|
|
1348
1347
|
v.offset = start + v.offset - prefix.length;
|
|
@@ -4,7 +4,7 @@ exports.parseScriptRanges = void 0;
|
|
|
4
4
|
const scriptSetupRanges_1 = require("./scriptSetupRanges");
|
|
5
5
|
function parseScriptRanges(ts, ast, hasScriptSetup, withNode) {
|
|
6
6
|
let exportDefault;
|
|
7
|
-
const bindings = hasScriptSetup ? (0, scriptSetupRanges_1.parseBindingRanges)(ts, ast
|
|
7
|
+
const bindings = hasScriptSetup ? (0, scriptSetupRanges_1.parseBindingRanges)(ts, ast) : [];
|
|
8
8
|
ast.forEachChild(raw => {
|
|
9
9
|
if (ts.isExportAssignment(raw)) {
|
|
10
10
|
let node = raw;
|
|
@@ -6,19 +6,32 @@ export declare function parseScriptSetupRanges(ts: typeof import('typescript/lib
|
|
|
6
6
|
leadingCommentEndOffset: number;
|
|
7
7
|
importSectionEndOffset: number;
|
|
8
8
|
bindings: TextRange[];
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
9
|
+
props: {
|
|
10
|
+
name?: string | undefined;
|
|
11
|
+
define?: (TextRange & {
|
|
12
|
+
statement: TextRange;
|
|
13
|
+
arg?: TextRange | undefined;
|
|
14
|
+
typeArg?: TextRange | undefined;
|
|
15
|
+
}) | undefined;
|
|
16
|
+
withDefaults?: (TextRange & {
|
|
17
|
+
arg?: TextRange | undefined;
|
|
18
|
+
}) | undefined;
|
|
19
|
+
};
|
|
20
|
+
slots: {
|
|
21
|
+
name?: string | undefined;
|
|
22
|
+
define?: TextRange | undefined;
|
|
23
|
+
};
|
|
24
|
+
emits: {
|
|
25
|
+
name?: string | undefined;
|
|
26
|
+
define?: TextRange | undefined;
|
|
27
|
+
};
|
|
28
|
+
expose: {
|
|
29
|
+
name?: string | undefined;
|
|
30
|
+
define?: (TextRange & {
|
|
31
|
+
arg?: TextRange | undefined;
|
|
32
|
+
typeArg?: TextRange | undefined;
|
|
33
|
+
}) | undefined;
|
|
34
|
+
};
|
|
22
35
|
defineProp: {
|
|
23
36
|
name: TextRange | undefined;
|
|
24
37
|
nameIsString: boolean;
|
|
@@ -27,7 +40,7 @@ export declare function parseScriptSetupRanges(ts: typeof import('typescript/lib
|
|
|
27
40
|
required: boolean;
|
|
28
41
|
}[];
|
|
29
42
|
};
|
|
30
|
-
export declare function parseBindingRanges(ts: typeof import('typescript/lib/tsserverlibrary'), sourceFile: ts.SourceFile
|
|
43
|
+
export declare function parseBindingRanges(ts: typeof import('typescript/lib/tsserverlibrary'), sourceFile: ts.SourceFile): TextRange[];
|
|
31
44
|
export declare function findBindingVars(ts: typeof import('typescript/lib/tsserverlibrary'), left: ts.BindingName, sourceFile: ts.SourceFile): TextRange[];
|
|
32
45
|
export declare function getStartEnd(node: ts.Node, sourceFile: ts.SourceFile): {
|
|
33
46
|
start: number;
|
|
@@ -4,23 +4,14 @@ exports.getStartEnd = exports.findBindingVars = exports.parseBindingRanges = exp
|
|
|
4
4
|
function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
5
5
|
let foundNonImportExportNode = false;
|
|
6
6
|
let importSectionEndOffset = 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
let propsRuntimeArg;
|
|
12
|
-
let propsTypeArg;
|
|
13
|
-
let defineSlots;
|
|
14
|
-
let defineEmits;
|
|
15
|
-
let defineExpose;
|
|
16
|
-
let slotsAssignName;
|
|
17
|
-
let emitsAssignName;
|
|
18
|
-
let exposeRuntimeArg;
|
|
19
|
-
let exposeTypeArg;
|
|
7
|
+
const props = {};
|
|
8
|
+
const slots = {};
|
|
9
|
+
const emits = {};
|
|
10
|
+
const expose = {};
|
|
20
11
|
const definePropProposalA = vueCompilerOptions.experimentalDefinePropProposal === 'kevinEdition' || ast.getFullText().trimStart().startsWith('// @experimentalDefinePropProposal=kevinEdition');
|
|
21
12
|
const definePropProposalB = vueCompilerOptions.experimentalDefinePropProposal === 'johnsonEdition' || ast.getFullText().trimStart().startsWith('// @experimentalDefinePropProposal=johnsonEdition');
|
|
22
13
|
const defineProp = [];
|
|
23
|
-
const bindings = parseBindingRanges(ts, ast
|
|
14
|
+
const bindings = parseBindingRanges(ts, ast);
|
|
24
15
|
const text = ast.getFullText();
|
|
25
16
|
const leadingCommentEndOffset = ts.getLeadingCommentRanges(text, 0)?.reverse()[0].end ?? 0;
|
|
26
17
|
ast.forEachChild(node => {
|
|
@@ -42,30 +33,22 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
42
33
|
foundNonImportExportNode = true;
|
|
43
34
|
}
|
|
44
35
|
});
|
|
45
|
-
ast.forEachChild(child => visitNode(child, ast));
|
|
36
|
+
ast.forEachChild(child => visitNode(child, [ast]));
|
|
46
37
|
return {
|
|
47
38
|
leadingCommentEndOffset,
|
|
48
39
|
importSectionEndOffset,
|
|
49
40
|
bindings,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
defineEmits,
|
|
55
|
-
defineExpose,
|
|
56
|
-
propsAssignName,
|
|
57
|
-
propsRuntimeArg,
|
|
58
|
-
propsTypeArg,
|
|
59
|
-
slotsAssignName,
|
|
60
|
-
emitsAssignName,
|
|
61
|
-
exposeRuntimeArg,
|
|
62
|
-
exposeTypeArg,
|
|
41
|
+
props,
|
|
42
|
+
slots,
|
|
43
|
+
emits,
|
|
44
|
+
expose,
|
|
63
45
|
defineProp,
|
|
64
46
|
};
|
|
65
47
|
function _getStartEnd(node) {
|
|
66
48
|
return getStartEnd(node, ast);
|
|
67
49
|
}
|
|
68
|
-
function visitNode(node,
|
|
50
|
+
function visitNode(node, parents) {
|
|
51
|
+
const parent = parents[parents.length - 1];
|
|
69
52
|
if (ts.isCallExpression(node)
|
|
70
53
|
&& ts.isIdentifier(node.expression)) {
|
|
71
54
|
const callText = node.expression.getText(ast);
|
|
@@ -145,90 +128,102 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
145
128
|
}
|
|
146
129
|
}
|
|
147
130
|
else if (vueCompilerOptions.macros.defineSlots.includes(callText)) {
|
|
148
|
-
|
|
131
|
+
slots.define = _getStartEnd(node);
|
|
149
132
|
if (ts.isVariableDeclaration(parent)) {
|
|
150
|
-
|
|
133
|
+
slots.name = parent.name.getText(ast);
|
|
151
134
|
}
|
|
152
135
|
}
|
|
153
136
|
else if (vueCompilerOptions.macros.defineEmits.includes(callText)) {
|
|
154
|
-
|
|
137
|
+
emits.define = _getStartEnd(node);
|
|
155
138
|
if (ts.isVariableDeclaration(parent)) {
|
|
156
|
-
|
|
139
|
+
emits.name = parent.name.getText(ast);
|
|
157
140
|
}
|
|
158
141
|
}
|
|
159
142
|
else if (vueCompilerOptions.macros.defineExpose.includes(callText)) {
|
|
160
|
-
|
|
143
|
+
expose.define = _getStartEnd(node);
|
|
161
144
|
if (node.arguments.length) {
|
|
162
|
-
|
|
145
|
+
expose.define.arg = _getStartEnd(node.arguments[0]);
|
|
163
146
|
}
|
|
164
147
|
if (node.typeArguments?.length) {
|
|
165
|
-
|
|
148
|
+
expose.define.typeArg = _getStartEnd(node.typeArguments[0]);
|
|
166
149
|
}
|
|
167
150
|
}
|
|
168
151
|
else if (vueCompilerOptions.macros.defineProps.includes(callText)) {
|
|
169
|
-
|
|
152
|
+
let statementRange;
|
|
153
|
+
for (let i = parents.length - 1; i >= 0; i--) {
|
|
154
|
+
if (ts.isStatement(parents[i])) {
|
|
155
|
+
const statement = parents[i];
|
|
156
|
+
statement.forEachChild(child => {
|
|
157
|
+
const range = _getStartEnd(child);
|
|
158
|
+
statementRange ??= range;
|
|
159
|
+
statementRange.end = range.end;
|
|
160
|
+
});
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (!statementRange) {
|
|
165
|
+
statementRange = _getStartEnd(node);
|
|
166
|
+
}
|
|
167
|
+
props.define = {
|
|
168
|
+
..._getStartEnd(node),
|
|
169
|
+
statement: statementRange,
|
|
170
|
+
};
|
|
170
171
|
if (ts.isVariableDeclaration(parent)) {
|
|
171
|
-
|
|
172
|
+
props.name = parent.name.getText(ast);
|
|
172
173
|
}
|
|
173
174
|
if (node.arguments.length) {
|
|
174
|
-
|
|
175
|
+
props.define.arg = _getStartEnd(node.arguments[0]);
|
|
175
176
|
}
|
|
176
177
|
if (node.typeArguments?.length) {
|
|
177
|
-
|
|
178
|
+
props.define.typeArg = _getStartEnd(node.typeArguments[0]);
|
|
178
179
|
}
|
|
179
180
|
}
|
|
180
181
|
else if (vueCompilerOptions.macros.withDefaults.includes(callText)) {
|
|
181
|
-
withDefaults = _getStartEnd(node);
|
|
182
|
+
props.withDefaults = _getStartEnd(node);
|
|
182
183
|
if (node.arguments.length >= 2) {
|
|
183
184
|
const arg = node.arguments[1];
|
|
184
|
-
|
|
185
|
+
props.withDefaults.arg = _getStartEnd(arg);
|
|
185
186
|
}
|
|
186
187
|
if (ts.isVariableDeclaration(parent)) {
|
|
187
|
-
|
|
188
|
+
props.name = parent.name.getText(ast);
|
|
188
189
|
}
|
|
189
190
|
}
|
|
190
191
|
}
|
|
191
|
-
node.forEachChild(child =>
|
|
192
|
+
node.forEachChild(child => {
|
|
193
|
+
parents.push(node);
|
|
194
|
+
visitNode(child, parents);
|
|
195
|
+
parents.pop();
|
|
196
|
+
});
|
|
192
197
|
}
|
|
193
198
|
}
|
|
194
199
|
exports.parseScriptSetupRanges = parseScriptSetupRanges;
|
|
195
|
-
function parseBindingRanges(ts, sourceFile
|
|
200
|
+
function parseBindingRanges(ts, sourceFile) {
|
|
196
201
|
const bindings = [];
|
|
197
202
|
sourceFile.forEachChild(node => {
|
|
198
|
-
if (
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
bindings.push(_var);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
else if (ts.isFunctionDeclaration(node)) {
|
|
208
|
-
if (node.name && ts.isIdentifier(node.name)) {
|
|
209
|
-
bindings.push(_getStartEnd(node.name));
|
|
203
|
+
if (ts.isVariableStatement(node)) {
|
|
204
|
+
for (const node_2 of node.declarationList.declarations) {
|
|
205
|
+
const vars = _findBindingVars(node_2.name);
|
|
206
|
+
for (const _var of vars) {
|
|
207
|
+
bindings.push(_var);
|
|
210
208
|
}
|
|
211
209
|
}
|
|
212
|
-
else if (ts.isClassDeclaration(node)) {
|
|
213
|
-
if (node.name) {
|
|
214
|
-
bindings.push(_getStartEnd(node.name));
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
else if (ts.isEnumDeclaration(node)) {
|
|
218
|
-
bindings.push(_getStartEnd(node.name));
|
|
219
|
-
}
|
|
220
210
|
}
|
|
221
|
-
else {
|
|
222
|
-
if (ts.
|
|
211
|
+
else if (ts.isFunctionDeclaration(node)) {
|
|
212
|
+
if (node.name && ts.isIdentifier(node.name)) {
|
|
223
213
|
bindings.push(_getStartEnd(node.name));
|
|
224
214
|
}
|
|
225
|
-
|
|
215
|
+
}
|
|
216
|
+
else if (ts.isClassDeclaration(node)) {
|
|
217
|
+
if (node.name) {
|
|
226
218
|
bindings.push(_getStartEnd(node.name));
|
|
227
219
|
}
|
|
228
220
|
}
|
|
221
|
+
else if (ts.isEnumDeclaration(node)) {
|
|
222
|
+
bindings.push(_getStartEnd(node.name));
|
|
223
|
+
}
|
|
229
224
|
if (ts.isImportDeclaration(node)) {
|
|
230
|
-
if (node.importClause &&
|
|
231
|
-
if (node.importClause.name
|
|
225
|
+
if (node.importClause && !node.importClause.isTypeOnly) {
|
|
226
|
+
if (node.importClause.name) {
|
|
232
227
|
bindings.push(_getStartEnd(node.importClause.name));
|
|
233
228
|
}
|
|
234
229
|
if (node.importClause.namedBindings) {
|
package/out/plugins/vue-tsx.d.ts
CHANGED
|
@@ -16,19 +16,32 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
16
16
|
leadingCommentEndOffset: number;
|
|
17
17
|
importSectionEndOffset: number;
|
|
18
18
|
bindings: import("../types").TextRange[];
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
19
|
+
props: {
|
|
20
|
+
name?: string | undefined;
|
|
21
|
+
define?: (import("../types").TextRange & {
|
|
22
|
+
statement: import("../types").TextRange;
|
|
23
|
+
arg?: import("../types").TextRange | undefined;
|
|
24
|
+
typeArg?: import("../types").TextRange | undefined;
|
|
25
|
+
}) | undefined;
|
|
26
|
+
withDefaults?: (import("../types").TextRange & {
|
|
27
|
+
arg?: import("../types").TextRange | undefined;
|
|
28
|
+
}) | undefined;
|
|
29
|
+
};
|
|
30
|
+
slots: {
|
|
31
|
+
name?: string | undefined;
|
|
32
|
+
define?: import("../types").TextRange | undefined;
|
|
33
|
+
};
|
|
34
|
+
emits: {
|
|
35
|
+
name?: string | undefined;
|
|
36
|
+
define?: import("../types").TextRange | undefined;
|
|
37
|
+
};
|
|
38
|
+
expose: {
|
|
39
|
+
name?: string | undefined;
|
|
40
|
+
define?: (import("../types").TextRange & {
|
|
41
|
+
arg?: import("../types").TextRange | undefined;
|
|
42
|
+
typeArg?: import("../types").TextRange | undefined;
|
|
43
|
+
}) | undefined;
|
|
44
|
+
};
|
|
32
45
|
defineProp: {
|
|
33
46
|
name: import("../types").TextRange | undefined;
|
|
34
47
|
nameIsString: boolean;
|
|
@@ -38,12 +51,12 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
38
51
|
}[];
|
|
39
52
|
} | undefined>;
|
|
40
53
|
lang: import("@vue/reactivity").ComputedRef<string>;
|
|
41
|
-
|
|
54
|
+
generatedScript: import("@vue/reactivity").ComputedRef<{
|
|
42
55
|
codes: muggle.Segment<import("@volar/language-core").FileRangeCapabilities>[];
|
|
43
56
|
codeStacks: muggle.StackNode[];
|
|
44
57
|
mirrorBehaviorMappings: import("@volar/source-map").Mapping<[import("@volar/language-core").MirrorBehaviorCapabilities, import("@volar/language-core").MirrorBehaviorCapabilities]>[];
|
|
45
58
|
}>;
|
|
46
|
-
|
|
59
|
+
generatedTemplate: import("@vue/reactivity").ComputedRef<{
|
|
47
60
|
codes: (string | [string, string | undefined, number | [number, number], import("@volar/language-core").FileRangeCapabilities])[];
|
|
48
61
|
codeStacks: muggle.StackNode[];
|
|
49
62
|
formatCodes: (string | [string, string | undefined, number | [number, number], import("@volar/language-core").FileRangeCapabilities])[];
|
|
@@ -51,7 +64,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
51
64
|
cssCodes: (string | [string, string | undefined, number | [number, number], import("@volar/language-core").FileRangeCapabilities])[];
|
|
52
65
|
cssCodeStacks: muggle.StackNode[];
|
|
53
66
|
tagNames: Record<string, number[]>;
|
|
54
|
-
|
|
67
|
+
accessedGlobalVariables: Set<string>;
|
|
55
68
|
hasSlot: boolean;
|
|
56
69
|
} | undefined>;
|
|
57
70
|
}>;
|
package/out/plugins/vue-tsx.js
CHANGED
|
@@ -26,7 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
exports.tsCodegen = void 0;
|
|
27
27
|
const reactivity_1 = require("@vue/reactivity");
|
|
28
28
|
const script_1 = require("../generators/script");
|
|
29
|
-
const
|
|
29
|
+
const template_1 = require("../generators/template");
|
|
30
30
|
const scriptRanges_1 = require("../parsers/scriptRanges");
|
|
31
31
|
const scriptSetupRanges_1 = require("../parsers/scriptSetupRanges");
|
|
32
32
|
const language_core_1 = require("@volar/language-core");
|
|
@@ -64,7 +64,7 @@ const plugin = (ctx) => {
|
|
|
64
64
|
documentFormatting: false,
|
|
65
65
|
documentSymbol: false,
|
|
66
66
|
};
|
|
67
|
-
const tsx = _tsx.
|
|
67
|
+
const tsx = _tsx.generatedScript.value;
|
|
68
68
|
if (tsx) {
|
|
69
69
|
const [content, contentStacks] = ctx.codegenStack ? muggle.track([...tsx.codes], [...tsx.codeStacks]) : [[...tsx.codes], [...tsx.codeStacks]];
|
|
70
70
|
embeddedFile.content = content;
|
|
@@ -82,8 +82,8 @@ const plugin = (ctx) => {
|
|
|
82
82
|
codeAction: false,
|
|
83
83
|
inlayHint: false,
|
|
84
84
|
};
|
|
85
|
-
if (_tsx.
|
|
86
|
-
const [content, contentStacks] = ctx.codegenStack ? muggle.track([..._tsx.
|
|
85
|
+
if (_tsx.generatedTemplate.value) {
|
|
86
|
+
const [content, contentStacks] = ctx.codegenStack ? muggle.track([..._tsx.generatedTemplate.value.formatCodes], [..._tsx.generatedTemplate.value.formatCodeStacks]) : [[..._tsx.generatedTemplate.value.formatCodes], [..._tsx.generatedTemplate.value.formatCodeStacks]];
|
|
87
87
|
embeddedFile.content = content;
|
|
88
88
|
embeddedFile.contentStacks = contentStacks;
|
|
89
89
|
}
|
|
@@ -103,8 +103,8 @@ const plugin = (ctx) => {
|
|
|
103
103
|
}
|
|
104
104
|
else if (suffix.match(templateStyleCssReg)) {
|
|
105
105
|
embeddedFile.parentFileName = fileName + '.template.' + sfc.template?.lang;
|
|
106
|
-
if (_tsx.
|
|
107
|
-
const [content, contentStacks] = ctx.codegenStack ? muggle.track([..._tsx.
|
|
106
|
+
if (_tsx.generatedTemplate.value) {
|
|
107
|
+
const [content, contentStacks] = ctx.codegenStack ? muggle.track([..._tsx.generatedTemplate.value.cssCodes], [..._tsx.generatedTemplate.value.cssCodeStacks]) : [[..._tsx.generatedTemplate.value.cssCodes], [..._tsx.generatedTemplate.value.cssCodeStacks]];
|
|
108
108
|
embeddedFile.content = content;
|
|
109
109
|
embeddedFile.contentStacks = contentStacks;
|
|
110
110
|
}
|
|
@@ -135,28 +135,28 @@ function createTsx(fileName, _sfc, { vueCompilerOptions, compilerOptions, codege
|
|
|
135
135
|
const scriptSetupRanges = (0, reactivity_1.computed)(() => _sfc.scriptSetupAst
|
|
136
136
|
? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, _sfc.scriptSetupAst, vueCompilerOptions)
|
|
137
137
|
: undefined);
|
|
138
|
-
const
|
|
138
|
+
const generatedTemplate = (0, reactivity_1.computed)(() => {
|
|
139
139
|
if (!_sfc.templateAst)
|
|
140
140
|
return;
|
|
141
|
-
return
|
|
141
|
+
return (0, template_1.generate)(ts, compilerOptions, vueCompilerOptions, _sfc.template?.content ?? '', _sfc.template?.lang ?? 'html', _sfc, hasScriptSetupSlots.value, slotsAssignName.value, propsAssignName.value, codegenStack);
|
|
142
142
|
});
|
|
143
143
|
//#region remove when https://github.com/vuejs/core/pull/5912 merged
|
|
144
144
|
const hasScriptSetupSlots = (0, reactivity_1.shallowRef)(false);
|
|
145
145
|
const slotsAssignName = (0, reactivity_1.shallowRef)();
|
|
146
146
|
const propsAssignName = (0, reactivity_1.shallowRef)();
|
|
147
147
|
//#endregion
|
|
148
|
-
const
|
|
149
|
-
hasScriptSetupSlots.value = !!scriptSetupRanges.value?.
|
|
150
|
-
slotsAssignName.value = scriptSetupRanges.value?.
|
|
151
|
-
propsAssignName.value = scriptSetupRanges.value?.
|
|
152
|
-
return (0, script_1.generate)(ts, fileName, _sfc, lang.value, scriptRanges.value, scriptSetupRanges.value,
|
|
148
|
+
const generatedScript = (0, reactivity_1.computed)(() => {
|
|
149
|
+
hasScriptSetupSlots.value = !!scriptSetupRanges.value?.slots.define;
|
|
150
|
+
slotsAssignName.value = scriptSetupRanges.value?.slots.name;
|
|
151
|
+
propsAssignName.value = scriptSetupRanges.value?.props.name;
|
|
152
|
+
return (0, script_1.generate)(ts, fileName, _sfc, lang.value, scriptRanges.value, scriptSetupRanges.value, generatedTemplate.value, compilerOptions, vueCompilerOptions, codegenStack);
|
|
153
153
|
});
|
|
154
154
|
return {
|
|
155
155
|
scriptRanges,
|
|
156
156
|
scriptSetupRanges,
|
|
157
157
|
lang,
|
|
158
|
-
|
|
159
|
-
|
|
158
|
+
generatedScript,
|
|
159
|
+
generatedTemplate,
|
|
160
160
|
};
|
|
161
161
|
}
|
|
162
162
|
//# sourceMappingURL=vue-tsx.js.map
|
package/out/utils/transform.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
2
2
|
import { VueCompilerOptions } from '../types';
|
|
3
|
-
export declare function walkInterpolationFragment(ts: typeof import('typescript/lib/tsserverlibrary'), code: string, ast: ts.SourceFile, cb: (fragment: string, offset: number | undefined, isJustForErrorMapping?: boolean) => void, localVars:
|
|
3
|
+
export declare function walkInterpolationFragment(ts: typeof import('typescript/lib/tsserverlibrary'), code: string, ast: ts.SourceFile, cb: (fragment: string, offset: number | undefined, isJustForErrorMapping?: boolean) => void, localVars: Map<string, number>, identifiers: Set<string>, vueOptions: VueCompilerOptions): {
|
|
4
4
|
text: string;
|
|
5
5
|
isShorthand: boolean;
|
|
6
6
|
offset: number;
|
package/out/utils/transform.js
CHANGED
|
@@ -5,7 +5,7 @@ const shared_1 = require("@vue/shared");
|
|
|
5
5
|
function walkInterpolationFragment(ts, code, ast, cb, localVars, identifiers, vueOptions) {
|
|
6
6
|
let ctxVars = [];
|
|
7
7
|
const varCb = (id, isShorthand) => {
|
|
8
|
-
if (
|
|
8
|
+
if (localVars.get(id.text) ||
|
|
9
9
|
// https://github.com/vuejs/core/blob/245230e135152900189f13a4281302de45fdcfaa/packages/compiler-core/src/transforms/transformExpression.ts#L342-L352
|
|
10
10
|
(0, shared_1.isGloballyWhitelisted)(id.text) ||
|
|
11
11
|
id.text === 'require' ||
|
|
@@ -101,7 +101,7 @@ function walkIdentifiers(ts, node, cb, localVars, blockVars = [], isRoot = true)
|
|
|
101
101
|
else if (ts.isVariableDeclaration(node)) {
|
|
102
102
|
colletVars(ts, node.name, blockVars);
|
|
103
103
|
for (const varName of blockVars) {
|
|
104
|
-
localVars
|
|
104
|
+
localVars.set(varName, (localVars.get(varName) ?? 0) + 1);
|
|
105
105
|
}
|
|
106
106
|
if (node.initializer)
|
|
107
107
|
walkIdentifiers(ts, node.initializer, cb, localVars, blockVars, false);
|
|
@@ -115,10 +115,10 @@ function walkIdentifiers(ts, node, cb, localVars, blockVars = [], isRoot = true)
|
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
for (const varName of functionArgs)
|
|
118
|
-
localVars
|
|
118
|
+
localVars.set(varName, (localVars.get(varName) ?? 0) + 1);
|
|
119
119
|
walkIdentifiers(ts, node.body, cb, localVars, blockVars, false);
|
|
120
120
|
for (const varName of functionArgs)
|
|
121
|
-
localVars
|
|
121
|
+
localVars.set(varName, localVars.get(varName) - 1);
|
|
122
122
|
}
|
|
123
123
|
else if (ts.isObjectLiteralExpression(node)) {
|
|
124
124
|
for (const prop of node.properties) {
|
|
@@ -152,14 +152,14 @@ function walkIdentifiers(ts, node, cb, localVars, blockVars = [], isRoot = true)
|
|
|
152
152
|
node.forEachChild(node => walkIdentifiers(ts, node, cb, localVars, blockVars, false));
|
|
153
153
|
if (ts.isBlock(node)) {
|
|
154
154
|
for (const varName of blockVars) {
|
|
155
|
-
localVars
|
|
155
|
+
localVars.set(varName, localVars.get(varName) - 1);
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
158
|
blockVars = _blockVars;
|
|
159
159
|
}
|
|
160
160
|
if (isRoot) {
|
|
161
161
|
for (const varName of blockVars) {
|
|
162
|
-
localVars
|
|
162
|
+
localVars.set(varName, localVars.get(varName) - 1);
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
165
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/language-core",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.19",
|
|
4
4
|
"main": "out/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"directory": "packages/vue-language-core"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@volar/language-core": "~1.10.
|
|
17
|
-
"@volar/source-map": "~1.10.
|
|
16
|
+
"@volar/language-core": "~1.10.4",
|
|
17
|
+
"@volar/source-map": "~1.10.4",
|
|
18
18
|
"@vue/compiler-dom": "^3.3.0",
|
|
19
19
|
"@vue/reactivity": "^3.3.0",
|
|
20
20
|
"@vue/shared": "^3.3.0",
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"optional": true
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "2e17f3c9cfa827c71e1ed07331730b3ee2596b76"
|
|
38
38
|
}
|