Skip to content

Commit 08e22d9

Browse files
committed
Merge branch 'master' of https://github.com/vuejs/language-tools into feat/split-strictTemplates
2 parents 01fc1b8 + baa1319 commit 08e22d9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+911
-603
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,15 @@ lspconfig.tsserver.setup {
9797
},
9898
},
9999
},
100+
}
100101

101102
lspconfig.volar.setup {
102103
init_options = {
103104
vue = {
104105
hybridMode = false,
105106
},
106107
},
107-
},
108+
}
108109
```
109110

110111
### nvim-cmp integration

packages/component-meta/lib/base.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ function createSchemaResolvers(
540540
function resolveSlotProperties(prop: ts.Symbol): SlotMeta {
541541
const propType = typeChecker.getNonNullableType(typeChecker.getTypeOfSymbolAtLocation(prop, symbolNode));
542542
const signatures = propType.getCallSignatures();
543-
const paramType = signatures[0].parameters[0];
543+
const paramType = signatures[0]?.parameters[0];
544544
const subtype = paramType ? typeChecker.getTypeOfSymbolAtLocation(paramType, symbolNode) : typeChecker.getAnyType();
545545
let schema: PropertyMetaSchema;
546546
let declarations: Declaration[];
@@ -721,7 +721,7 @@ function readVueComponentDefaultProps(
721721

722722
function scriptSetupWorker() {
723723

724-
const descriptor = vueSourceFile.sfc;
724+
const descriptor = vueSourceFile._sfc;
725725
const scriptSetupRanges = descriptor.scriptSetup ? vue.parseScriptSetupRanges(ts, descriptor.scriptSetup.ast, vueCompilerOptions) : undefined;
726726

727727
if (descriptor.scriptSetup && scriptSetupRanges?.props.withDefaults?.arg) {
@@ -772,7 +772,7 @@ function readVueComponentDefaultProps(
772772

773773
function scriptWorker() {
774774

775-
const descriptor = vueSourceFile.sfc;
775+
const descriptor = vueSourceFile._sfc;
776776

777777
if (descriptor.script) {
778778
const scriptResult = readTsComponentDefaultProps(descriptor.script.lang, descriptor.script.content, 'default', printer, ts);

packages/component-meta/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"**/*.js",
77
"**/*.d.ts"
88
],
9+
"sideEffects": false,
910
"repository": {
1011
"type": "git",
1112
"url": "https://github.com/vuejs/language-tools.git",

packages/component-type-helpers/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"**/*.js",
77
"**/*.d.ts"
88
],
9+
"sideEffects": false,
910
"repository": {
1011
"type": "git",
1112
"url": "https://github.com/vuejs/language-tools.git",

packages/language-core/lib/codegen/globalTypes.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export function generateGlobalTypes(options: VueCompilerOptions) {
9494
'__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: infer Ctx } ? Ctx : never : any
9595
, T extends (props: any, ctx: infer Ctx) => any ? Ctx : any
9696
>>;
97+
type __VLS_UseTemplateRef<T> = Readonly<import('${lib}').ShallowRef<T | null>>;
9798
9899
function __VLS_getVForSourceType(source: number): [number, number, number][];
99100
function __VLS_getVForSourceType(source: string): [string, number, number][];
@@ -122,9 +123,11 @@ export function generateGlobalTypes(options: VueCompilerOptions) {
122123
function __VLS_getSlotParams<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>;
123124
// @ts-ignore
124125
function __VLS_getSlotParam<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>[0];
125-
function __VLS_directiveAsFunction<T extends import('${lib}').Directive>(dir: T): T extends (...args: any) => any
126-
? T | __VLS_unknownDirective
127-
: NonNullable<(T & Record<string, __VLS_unknownDirective>)['created' | 'beforeMount' | 'mounted' | 'beforeUpdate' | 'updated' | 'beforeUnmount' | 'unmounted']>;
126+
function __VLS_asFunctionalDirective<T>(dir: T): T extends import('${lib}').ObjectDirective
127+
? NonNullable<T['created' | 'beforeMount' | 'mounted' | 'beforeUpdate' | 'updated' | 'beforeUnmount' | 'unmounted']>
128+
: T extends (...args: any) => any
129+
? T
130+
: __VLS_unknownDirective;
128131
function __VLS_withScope<T, K>(ctx: T, scope: K): ctx is T & K;
129132
function __VLS_makeOptional<T>(t: T): { [K in keyof T]?: T[K] };
130133
function __VLS_nonNullable<T>(t: T): T extends null | undefined ? never : T;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type * as CompilerDOM from '@vue/compiler-dom';
2+
3+
export interface InlayHintInfo {
4+
blockName: string;
5+
offset: number;
6+
setting: string;
7+
label: string;
8+
tooltip?: string;
9+
paddingRight?: boolean;
10+
paddingLeft?: boolean;
11+
}
12+
13+
export function createVBindShorthandInlayHintInfo(loc: CompilerDOM.SourceLocation, variableName: string): InlayHintInfo {
14+
return {
15+
blockName: 'template',
16+
offset: loc.end.offset,
17+
setting: 'vue.inlayHints.vBindShorthand',
18+
label: `="${variableName}"`,
19+
tooltip: [
20+
`This is a shorthand for \`${loc.source}="${variableName}"\`.`,
21+
'To hide this hint, set `vue.inlayHints.vBindShorthand` to `false` in IDE settings.',
22+
'[More info](https://github.com/vuejs/core/pull/9451)',
23+
].join('\n\n'),
24+
};
25+
}

packages/language-core/lib/codegen/script/component.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export function* generateComponent(
3030
yield `}${endOfLine}`;
3131
yield `},${newLine}`;
3232
if (!ctx.bypassDefineComponent) {
33-
const emitOptionCodes = [...generateEmitsOption(options, scriptSetup, scriptSetupRanges)];
33+
const emitOptionCodes = [...generateEmitsOption(options, scriptSetupRanges)];
3434
for (const code of emitOptionCodes) {
3535
yield code;
3636
}
@@ -64,7 +64,6 @@ export function* generateComponentSetupReturns(scriptSetupRanges: ScriptSetupRan
6464

6565
export function* generateEmitsOption(
6666
options: ScriptCodegenOptions,
67-
scriptSetup: NonNullable<Sfc['scriptSetup']>,
6867
scriptSetupRanges: ScriptSetupRanges
6968
): Generator<Code> {
7069
const codes: {
@@ -75,16 +74,16 @@ export function* generateEmitsOption(
7574
}[] = [];
7675
if (scriptSetupRanges.defineProp.some(p => p.isModel)) {
7776
codes.push({
78-
optionExp: `{} as __VLS_NormalizeEmits<__VLS_ModelEmitsType>`,
79-
typeOptionType: `__VLS_ModelEmitsType`,
77+
optionExp: `{} as __VLS_NormalizeEmits<typeof __VLS_modelEmit>`,
78+
typeOptionType: `__VLS_ModelEmit`,
8079
});
8180
}
8281
if (scriptSetupRanges.emits.define) {
8382
const { typeArg, hasUnionTypeArg } = scriptSetupRanges.emits.define;
8483
codes.push({
8584
optionExp: `{} as __VLS_NormalizeEmits<typeof ${scriptSetupRanges.emits.name ?? '__VLS_emit'}>`,
8685
typeOptionType: typeArg && !hasUnionTypeArg
87-
? scriptSetup.content.slice(typeArg.start, typeArg.end)
86+
? `__VLS_Emit`
8887
: undefined,
8988
});
9089
}

packages/language-core/lib/codegen/script/componentSelf.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export function* generateComponentSelf(
4848
yield `}${endOfLine}`; // return {
4949
yield `},${newLine}`; // setup() {
5050
if (options.sfc.scriptSetup && options.scriptSetupRanges && !ctx.bypassDefineComponent) {
51-
const emitOptionCodes = [...generateEmitsOption(options, options.sfc.scriptSetup, options.scriptSetupRanges)];
51+
const emitOptionCodes = [...generateEmitsOption(options, options.scriptSetupRanges)];
5252
for (const code of emitOptionCodes) {
5353
yield code;
5454
}

packages/language-core/lib/codegen/script/context.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { InlayHintInfo } from '../types';
1+
import { InlayHintInfo } from '../inlayHints';
22
import { getLocalTypesGenerator } from '../localTypes';
33
import type { ScriptCodegenOptions } from './index';
44

packages/language-core/lib/codegen/script/index.ts

+19-6
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import type { Code, Sfc, VueCodeInformation, VueCompilerOptions } from '../../ty
66
import { endOfLine, generateSfcBlockSection, newLine } from '../common';
77
import { generateGlobalTypes, resolveGlobalTypesName } from '../globalTypes';
88
import type { TemplateCodegenContext } from '../template/context';
9-
import { createScriptCodegenContext, ScriptCodegenContext } from './context';
109
import { generateComponentSelf } from './componentSelf';
10+
import { createScriptCodegenContext, ScriptCodegenContext } from './context';
1111
import { generateScriptSetup, generateScriptSetupImports } from './scriptSetup';
1212
import { generateSrc } from './src';
1313
import { generateStyleModulesType } from './styleModulesType';
@@ -56,7 +56,13 @@ export function* generateScript(options: ScriptCodegenOptions): Generator<Code,
5656
const ctx = createScriptCodegenContext(options);
5757

5858
if (options.vueCompilerOptions.__setupedGlobalTypes) {
59-
yield `/// <reference types=".vue-global-types/${resolveGlobalTypesName(options.vueCompilerOptions)}" />${newLine}`;
59+
const globalTypes = options.vueCompilerOptions.__setupedGlobalTypes;
60+
if (typeof globalTypes === 'object') {
61+
yield `/// <reference types="${globalTypes.absolutePath}" />${newLine}`;
62+
}
63+
else {
64+
yield `/// <reference types=".vue-global-types/${resolveGlobalTypesName(options.vueCompilerOptions)}" />${newLine}`;
65+
}
6066
}
6167
else {
6268
yield `/* placeholder */`;
@@ -79,6 +85,7 @@ export function* generateScript(options: ScriptCodegenOptions): Generator<Code,
7985
}
8086
else {
8187
yield generateSfcBlockSection(options.sfc.script, 0, options.sfc.script.content.length, codeFeatures.all);
88+
yield* generateScriptSectionPartiallyEnding(options.sfc.script.name, options.sfc.script.content.length, '#3632/both.vue');
8289
yield* generateScriptSetup(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
8390
}
8491
}
@@ -131,12 +138,12 @@ export function* generateScript(options: ScriptCodegenOptions): Generator<Code,
131138
yield* generateScriptSetup(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
132139
}
133140

134-
yield `;`;
141+
if (options.sfc.script) {
142+
yield* generateScriptSectionPartiallyEnding(options.sfc.script.name, options.sfc.script.content.length, '#3632/script.vue');
143+
}
135144
if (options.sfc.scriptSetup) {
136-
// #4569
137-
yield ['', 'scriptSetup', options.sfc.scriptSetup.content.length, codeFeatures.verification];
145+
yield* generateScriptSectionPartiallyEnding(options.sfc.scriptSetup.name, options.sfc.scriptSetup.content.length, '#4569/main.vue');
138146
}
139-
yield newLine;
140147

141148
if (!ctx.generatedTemplate) {
142149
yield `function __VLS_template() {${newLine}`;
@@ -163,6 +170,12 @@ export function* generateScript(options: ScriptCodegenOptions): Generator<Code,
163170
return ctx;
164171
}
165172

173+
export function* generateScriptSectionPartiallyEnding(source: string, end: number, mark: string): Generator<Code> {
174+
yield `;`;
175+
yield ['', source, end, codeFeatures.verification];
176+
yield `/* PartiallyEnd: ${mark} */${newLine}`;
177+
}
178+
166179
function* generateDefineProp(
167180
options: ScriptCodegenOptions,
168181
scriptSetup: NonNullable<Sfc['scriptSetup']>

0 commit comments

Comments
 (0)