Skip to content

Commit

Permalink
feat: support $slots
Browse files Browse the repository at this point in the history
close vuejs#539
  • Loading branch information
johnsoncodehk committed Sep 29, 2021
1 parent 8006027 commit 0adcbbd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export function generate(
}>,
}> = {};
const tagResolves: Record<string, {
name: string,
baseProps: string,
props: string,
emit: string,
Expand Down Expand Up @@ -213,6 +214,7 @@ export function generate(
}

tagResolves[tag] = {
name: var_correctTagName,
baseProps: var_baseProps,
props: var_props,
emit: var_emit,
Expand Down Expand Up @@ -1119,7 +1121,7 @@ export function generate(
slotName = prop.arg.content;
}
const diagStart = tsCodeGen.getText().length;
tsCodeGen.addText(`__VLS_wrapComponents['' as __VLS_GetComponentName<typeof __VLS_wrapComponents, '${parentEl.tag}'>].__VLS_slots`);
tsCodeGen.addText(`({ ...__VLS_getTemplateSlots(__VLS_wrapComponents[${tagResolves[parentEl.tag].name}]), ...__VLS_getScriptSlots(__VLS_rawComponents[${tagResolves[parentEl.tag].name}])})`);
const argRange = prop.arg
? {
start: prop.arg.loc.start.offset,
Expand Down
3 changes: 3 additions & 0 deletions packages/vscode-vue-languageservice/src/utils/globalDoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ declare global {
function __VLS_directiveFunction<T>(dir: T): T extends ObjectDirective<infer E, infer V> ? V extends { value: infer V_2 } ? (value: V_2) => void : (value: V) => void
: T extends FunctionDirective<infer E, infer V> ? V extends { value: infer V_2 } ? (value: V_2) => void : (value: V) => void : T;
function __VLS_getTemplateSlots<T>(t: T): T extends { __VLS_slots: infer S } ? S : {};
function __VLS_getScriptSlots<T>(t: T): T extends new (...args: any) => { $slots?: infer S } ? (S extends object ? S : {}) : {};
type __VLS_GetComponentName<T, K extends string> = K extends keyof T ? IsAny<T[K]> extends false ? K : __VLS_GetComponentName_CamelCase<T, CamelCase<K>> : __VLS_GetComponentName_CamelCase<T, CamelCase<K>>;
type __VLS_GetComponentName_CamelCase<T, K extends string> = K extends keyof T ? IsAny<T[K]> extends false ? K : __VLS_GetComponentName_CapitalCase<T, Capitalize<K>> : __VLS_GetComponentName_CapitalCase<T, Capitalize<K>>;
type __VLS_GetComponentName_CapitalCase<T, K> = K extends keyof T ? K : never;
Expand Down

0 comments on commit 0adcbbd

Please sign in to comment.