Skip to content

Commit

Permalink
chore: consider noPropertyAccessFromIndexSignature when generating …
Browse files Browse the repository at this point in the history
…virtual code

close #3106
  • Loading branch information
johnsoncodehk committed May 3, 2023
1 parent 717cb8c commit d740ea0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/vue-language-core/src/generators/template.ts
Expand Up @@ -62,6 +62,7 @@ type Code = Segment<FileRangeCapabilities>;

export function generate(
ts: typeof import('typescript/lib/tsserverlibrary'),
compilerOptions: ts.CompilerOptions,
vueCompilerOptions: VueCompilerOptions,
sourceTemplate: string,
sourceLang: string,
Expand Down Expand Up @@ -1767,7 +1768,7 @@ export function generate(

function createPropertyAccessCode(a: Code, astHolder?: any): Code[] {
const aStr = typeof a === 'string' ? a : a[0];
if (validTsVar.test(aStr)) {
if (!compilerOptions.noPropertyAccessFromIndexSignature && validTsVar.test(aStr)) {
return ['.', a];
}
else if (aStr.startsWith('[') && aStr.endsWith(']')) {
Expand Down
1 change: 1 addition & 0 deletions packages/vue-language-core/src/plugins/vue-tsx.ts
Expand Up @@ -138,6 +138,7 @@ const plugin: VueLanguagePlugin = ({ modules, vueCompilerOptions, compilerOption

return templateGen.generate(
ts,
compilerOptions,
vueCompilerOptions,
_sfc.template?.content ?? '',
_sfc.template?.lang ?? 'html',
Expand Down
14 changes: 14 additions & 0 deletions packages/vue-test-workspace/vue-tsc/#3106/main.vue
@@ -0,0 +1,14 @@
<script setup lang="ts">
let Comp: new () => {
$props: {};
$slots: {
[key: string]: string;
};
};
</script>

<template>
<Comp>
<template v-slot:slot-name></template>
</Comp>
</template>

0 comments on commit d740ea0

Please sign in to comment.