Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Aug 30, 2024
1 parent f9ece30 commit 2cc52bd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/language-core/lib/codegen/globalTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ declare function __VLS_asFunctionalComponent<T, K = T extends new (...args: any)
: T extends (...args: any) => any ? T
: (_: {}${strictTemplates ? '' : ' & Record<string, unknown>'}, ctx?: any) => { __ctx?: { attrs?: any, expose?: any, slots?: any, emit?: any, props?: {}${strictTemplates ? '' : ' & Record<string, unknown>'} } };
declare function __VLS_elementAsFunction<T>(tag: T, endTag?: T): (_: T${strictTemplates ? '' : ' & Record<string, unknown>'}) => void;
declare function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): Parameters<T>['length'] extends 2 ? [any] : [];
declare function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): 2 extends Parameters<T>['length'] ? [any] : [];
declare function __VLS_pickFunctionalComponentCtx<T, K>(comp: T, compInstance: K): NonNullable<__VLS_PickNotAny<
'__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: infer Ctx } ? Ctx : never : any
, T extends (props: any, ctx: infer Ctx) => any ? Ctx : any
Expand Down
9 changes: 7 additions & 2 deletions packages/language-core/lib/parsers/scriptSetupRanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export function parseScriptSetupRanges(
name?: string;
define?: ReturnType<typeof parseDefineFunction>;
}[] = [];

const definePropProposalA = vueCompilerOptions.experimentalDefinePropProposal === 'kevinEdition' || ast.text.trimStart().startsWith('// @experimentalDefinePropProposal=kevinEdition');
const definePropProposalB = vueCompilerOptions.experimentalDefinePropProposal === 'johnsonEdition' || ast.text.trimStart().startsWith('// @experimentalDefinePropProposal=johnsonEdition');
const defineProp: {
Expand All @@ -63,11 +62,12 @@ export function parseScriptSetupRanges(
required: boolean;
isModel?: boolean;
}[] = [];
const bindings = parseBindingRanges(ts, ast);
const text = ast.text;
const leadingCommentEndOffset = ts.getLeadingCommentRanges(text, 0)?.reverse()[0].end ?? 0;
const importComponentNames = new Set<string>();

let bindings = parseBindingRanges(ts, ast);

ts.forEachChild(ast, node => {
const isTypeExport = (ts.isTypeAliasDeclaration(node) || ts.isInterfaceDeclaration(node)) && node.modifiers?.some(mod => mod.kind === ts.SyntaxKind.ExportKeyword);
if (
Expand Down Expand Up @@ -102,6 +102,11 @@ export function parseScriptSetupRanges(
});
ts.forEachChild(ast, child => visitNode(child, [ast]));

bindings = bindings.filter(range => {
const name = ast.text.substring(range.start, range.end);
return templateRefs.every(ref => ref.name !== name);
});

return {
leadingCommentEndOffset,
importSectionEndOffset,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
declare module 'vue' {
declare module 'vue3.5' {
export interface GlobalComponents {
Generic: typeof import('./generic.vue')['default'];
}
}

export { };
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@ import { useTemplateRef } from 'vue';
import { exactType } from '../../shared';
const comp1 = useTemplateRef('generic');
if (comp1.value) {
exactType(comp1.value.foo, 1)
}
const comp2 = useTemplateRef('v-for');
if (comp2.value) exactType(comp2.value[0]?.foo, {} as number | undefined);
if (comp2.value) {
exactType(comp2.value[0]?.foo, {} as number | undefined);
}
const comp3 = useTemplateRef('a');
if (comp3.value) exactType(comp3.value?.href, {} as string | undefined);
if (comp3.value) {
exactType(comp3.value.href, {} as string | undefined);
}
</script>

<template>
<Generic ref="generic" :foo="1"></Generic>

{{ exactType(comp1.foo, 1) }}

<Generic v-for="i in 4" ref="v-for" :foo="i"></Generic>

<a ref="a"></a>
Expand Down

0 comments on commit 2cc52bd

Please sign in to comment.