Skip to content

Commit 710976a

Browse files
committed
refactor: merge options
1 parent 08e22d9 commit 710976a

File tree

6 files changed

+26
-28
lines changed

6 files changed

+26
-28
lines changed

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import { getSlotsPropertyName } from '../utils/shared';
22
import type { VueCompilerOptions } from '../types';
33

44
export function resolveGlobalTypesName(options: VueCompilerOptions) {
5-
const { lib, target, strictAttributes, strictComponents } = options;
6-
return `${lib}_${target}_${strictAttributes}_${strictComponents}.d.ts`;
5+
const { lib, target, strictTemplates } = options;
6+
return `${lib}_${target}_${strictTemplates.attributes}_${strictTemplates.components}.d.ts`;
77
}
88

99
export function generateGlobalTypes(options: VueCompilerOptions) {
10-
const { lib, target, strictAttributes, strictComponents } = options;
11-
const fnPropsType = `(K extends { $props: infer Props } ? Props : any)${strictAttributes ? '' : ' & Record<string, unknown>'}`;
10+
const { lib, target, strictTemplates } = options;
11+
const fnPropsType = `(K extends { $props: infer Props } ? Props : any)${strictTemplates.attributes ? '' : ' & Record<string, unknown>'}`;
1212
let text = ``;
1313
if (target < 3.5) {
1414
text += `
@@ -54,7 +54,7 @@ export function generateGlobalTypes(options: VueCompilerOptions) {
5454
N1 extends keyof __VLS_GlobalComponents ? N1 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N1] } :
5555
N2 extends keyof __VLS_GlobalComponents ? N2 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N2] } :
5656
N3 extends keyof __VLS_GlobalComponents ? N3 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N3] } :
57-
${strictComponents ? '{}' : '{ [K in N0]: unknown }'}
57+
${strictTemplates.components ? '{}' : '{ [K in N0]: unknown }'}
5858
type __VLS_FunctionalComponentProps<T, K> =
5959
'__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: { props?: infer P } } ? NonNullable<P> : never
6060
: T extends (props: infer P, ...args: any) => any ? P :
@@ -140,8 +140,8 @@ export function generateGlobalTypes(options: VueCompilerOptions) {
140140
} & { props?: ${fnPropsType}; expose?(exposed: K): void; } }
141141
: T extends () => any ? (props: {}, ctx?: any) => ReturnType<T>
142142
: T extends (...args: any) => any ? T
143-
: (_: {}${strictAttributes ? '' : ' & Record<string, unknown>'}, ctx?: any) => { __ctx?: { attrs?: any, expose?: any, slots?: any, emit?: any, props?: {}${strictAttributes ? '' : ' & Record<string, unknown>'} } };
144-
function __VLS_elementAsFunction<T>(tag: T, endTag?: T): (_: T${strictComponents ? '' : ' & Record<string, unknown>'}) => void;
143+
: (_: {}${strictTemplates.attributes ? '' : ' & Record<string, unknown>'}, ctx?: any) => { __ctx?: { attrs?: any, expose?: any, slots?: any, emit?: any, props?: {}${strictTemplates.attributes ? '' : ' & Record<string, unknown>'} } };
144+
function __VLS_elementAsFunction<T>(tag: T, endTag?: T): (_: T${strictTemplates.components ? '' : ' & Record<string, unknown>'}) => void;
145145
function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): 2 extends Parameters<T>['length'] ? [any] : [];
146146
function __VLS_normalizeSlot<S>(s: S): S extends () => infer R ? (props: {}) => R : S;
147147
function __VLS_tryAsConstant<const T>(t: T): T;

packages/language-core/lib/codegen/template/elementEvents.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function* generateElementEvents(
3838
? originalPropName
3939
: `'${originalPropName}'`;
4040
yield `const ${ctx.getInternalVariable()}: `;
41-
if (!options.vueCompilerOptions.strictAttributes) {
41+
if (!options.vueCompilerOptions.strictTemplates.attributes) {
4242
yield `Record<string, unknown> & `;
4343
}
4444
yield `(${newLine}`;

packages/language-core/lib/codegen/template/elementProps.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export function* generateElementProps(
123123
prop.arg.loc.start.offset,
124124
{
125125
...codeInfo,
126-
verification: options.vueCompilerOptions.strictAttributes
126+
verification: options.vueCompilerOptions.strictTemplates.attributes
127127
? codeInfo.verification
128128
: {
129129
shouldReport(_source, code) {
@@ -209,7 +209,7 @@ export function* generateElementProps(
209209
: {
210210
...ctx.codeFeatures.withoutHighlightAndCompletion,
211211
};
212-
if (!options.vueCompilerOptions.strictAttributes) {
212+
if (!options.vueCompilerOptions.strictTemplates.attributes) {
213213
const verification = codeInfo.verification;
214214
codeInfo.verification = {
215215
shouldReport(_source, code) {

packages/language-core/lib/types.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ export interface VueCompilerOptions {
2828
vitePressExtensions: string[];
2929
petiteVueExtensions: string[];
3030
jsxSlots: boolean;
31-
strictTemplates: boolean;
32-
strictAttributes: boolean;
33-
strictComponents: boolean;
31+
strictTemplates: {
32+
attributes: boolean;
33+
components: boolean;
34+
};
3435
skipTemplateCodegen: boolean;
3536
fallthroughAttributes: boolean;
3637
dataAttributes: string[];

packages/language-core/lib/utils/ts.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,13 @@ function getPartialVueCompilerOptions(
223223
export function resolveVueCompilerOptions(vueOptions: Partial<VueCompilerOptions>): VueCompilerOptions {
224224
const target = vueOptions.target ?? 3.3;
225225
const lib = vueOptions.lib ?? 'vue';
226-
const strictTemplates = vueOptions.strictTemplates ?? false;
226+
const strictTemplates = typeof vueOptions.strictTemplates === 'boolean' ? {
227+
attributes: vueOptions.strictTemplates,
228+
components: vueOptions.strictTemplates
229+
} : vueOptions.strictTemplates ?? {
230+
attributes: false,
231+
components: false
232+
}
227233
return {
228234
...vueOptions,
229235
target,
@@ -233,8 +239,6 @@ export function resolveVueCompilerOptions(vueOptions: Partial<VueCompilerOptions
233239
lib,
234240
jsxSlots: vueOptions.jsxSlots ?? false,
235241
strictTemplates,
236-
strictAttributes: vueOptions.strictAttributes ?? strictTemplates,
237-
strictComponents: vueOptions.strictComponents ?? strictTemplates,
238242
skipTemplateCodegen: vueOptions.skipTemplateCodegen ?? false,
239243
fallthroughAttributes: vueOptions.fallthroughAttributes ?? false,
240244
dataAttributes: vueOptions.dataAttributes ?? [],

packages/language-core/schemas/vue-tsconfig.schema.json

+5-12
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,13 @@
4141
"markdownDescription": "Generate slots type for `JSX.ElementChildrenAttribute`."
4242
},
4343
"strictTemplates": {
44-
"type": "boolean",
45-
"default": false,
44+
"type": ["boolean", "object"],
45+
"default": {
46+
"attributes": false,
47+
"components": false
48+
},
4649
"markdownDescription": "Strict props(attrs), component type-checking in templates."
4750
},
48-
"strictAttributes": {
49-
"type": "boolean",
50-
"default": false,
51-
"markdownDescription": "Strict props(attrs) type-checking in templates."
52-
},
53-
"strictComponents": {
54-
"type": "boolean",
55-
"default": false,
56-
"markdownDescription": "Strict component type-checking in templates."
57-
},
5851
"skipTemplateCodegen": {
5952
"type": "boolean",
6053
"default": false,

0 commit comments

Comments
 (0)