Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow data with the same name as components #3744

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/language-core/src/generators/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
codes.push(`let __VLS_otherComponents!: NonNullable<typeof __VLS_internalComponent extends { components: infer C } ? C : {}> & typeof __VLS_componentsOption;\n`);
codes.push(`let __VLS_own!: __VLS_SelfComponent<typeof __VLS_name, typeof __VLS_internalComponent & (new () => { ${getSlotsPropertyName(vueCompilerOptions.target)}: typeof ${scriptSetupRanges?.slots?.name ?? '__VLS_slots'} })>;\n`);
codes.push(`let __VLS_localComponents!: typeof __VLS_otherComponents & Omit<typeof __VLS_own, keyof typeof __VLS_otherComponents>;\n`);
codes.push(`let __VLS_components!: typeof __VLS_localComponents & __VLS_GlobalComponents & typeof __VLS_ctx;\n`); // for html completion, TS references...
codes.push(`let __VLS_components!: typeof __VLS_localComponents & Omit<__VLS_GlobalComponents, keyof typeof __VLS_ctx> & Omit<typeof __VLS_ctx, keyof typeof __VLS_localComponents>;\n`); // for html completion, TS references...

/* Style Scoped */
codes.push('/* Style Scoped */\n');
Expand Down
13 changes: 9 additions & 4 deletions packages/language-core/src/generators/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ export function generate(
let addedBlockCondition = false;

if (branch.condition?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
codes.push(` `);
codes.push(` (`);
const beforeCodeLength = codes.length;
codes.push(
...createInterpolationCode(
Expand All @@ -518,6 +518,11 @@ export function generate(
),
);
const afterCodeLength = codes.length;
codes.push(
` && __VLS_components`,
...createPropertyAccessCode(branch.condition.content),
)
codes.push(')');

formatCodes.push(
...createFormatCode(
Expand Down Expand Up @@ -688,14 +693,14 @@ export function generate(
);
for (const componentName of getPossibleOriginalComponentName(tag)) {
codes.push(
`'${componentName}' extends keyof typeof __VLS_ctx ? `,
`{ '${toCanonicalComponentName(tag)}': typeof __VLS_ctx`,
`'${componentName}' extends keyof typeof __VLS_components ? `,
`{ '${toCanonicalComponentName(tag)}': typeof __VLS_components`,
...createPropertyAccessCode(componentName),
` }: `,
);
}
codes.push(
`typeof __VLS_resolvedLocalAndGlobalComponents)`,
`typeof __VLS_ctx)`,
...(tagOffsets.length
? createPropertyAccessCode([
toCanonicalComponentName(tag),
Expand Down
5 changes: 5 additions & 0 deletions test-workspace/tsc/vue3/#3411/Comp.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script setup lang="ts">
defineEmits<{
(e: 'foo', arg: number): void
}>();
</script>
24 changes: 24 additions & 0 deletions test-workspace/tsc/vue3/#3411/main.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<script lang="ts">
import { defineComponent } from 'vue';
import Comp from './Comp.vue';
import { exactType } from '../../shared';

export default defineComponent({
components: {
Comp,
},
computed: {
Comp() {
return 123;
},
},
methods: {
exactType,
},
});
</script>

<template>
<Comp @foo="e => exactType(e, 1 as number)" />
{{ exactType(Comp, 123) }}
</template>
Loading