Skip to content

Commit

Permalink
fix: avoid reading props from __VLS_ctx (#3636)
Browse files Browse the repository at this point in the history
Co-authored-by: Johnson Chu <[email protected]>
  • Loading branch information
so1ve and johnsoncodehk authored Oct 8, 2023
1 parent 50be014 commit 828b9e5
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/vue-language-core/src/generators/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export function generate(
sfc: Sfc,
hasScriptSetupSlots: boolean,
slotsAssignName: string | undefined,
propsAssignName: string | undefined,
codegenStack: boolean,
) {

Expand All @@ -98,6 +99,10 @@ export function generate(
let expectedErrorStart: undefined | number;
let expectedErrorNode: CompilerDOM.CommentNode | undefined;

if (propsAssignName) {
localVars[propsAssignName] = 1;
}

generatePreResolveComponents();

if (sfc.templateAst) {
Expand Down
3 changes: 3 additions & 0 deletions packages/vue-language-core/src/plugins/vue-tsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,21 @@ function createTsx(fileName: string, _sfc: Sfc, { vueCompilerOptions, compilerOp
_sfc,
hasScriptSetupSlots.value,
slotsAssignName.value,
propsAssignName.value,
codegenStack,
);
});

//#region remove when https://github.com/vuejs/core/pull/5912 merged
const hasScriptSetupSlots = ref(false);
const slotsAssignName = ref<string>();
const propsAssignName = ref<string>();
//#endregion

const tsxGen = computed(() => {
hasScriptSetupSlots.value = !!scriptSetupRanges.value?.defineSlots;
slotsAssignName.value = scriptSetupRanges.value?.slotsAssignName;
propsAssignName.value = scriptSetupRanges.value?.propsAssignName;
return genScript(
ts,
fileName,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<script setup lang="ts" generic="T">
import { exactType } from 'vue-tsc/shared';
const props = withDefaults(defineProps<{
value?: T | null;
list?: T[];
}>(), {
value: null,
});
</script>

<template>
<div v-for="item of list">
{{ exactType(item, {} as T) }}
</div>
<div v-for="item of props.list">
{{ exactType(item, {} as T) }}
</div>
<div v-for="item of $props.list">
{{ exactType(item, {} as T) }}
</div>
</templat>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<script setup lang="ts" generic="T">
import { exactType } from 'vue-tsc/shared';
const props = defineProps<{
foo: T;
bar: string;
}>();
</script>

<template>
{{ exactType(props.bar, '' as string) }}
{{ exactType(props.foo, {} as T) }}
</template>

0 comments on commit 828b9e5

Please sign in to comment.