Skip to content

Commit

Permalink
fix: v-slot error when noPropertyAccessFromIndexSignature is enabled
Browse files Browse the repository at this point in the history
close #2236
  • Loading branch information
johnsoncodehk committed Dec 25, 2022
1 parent 2fb66c8 commit 3165a08
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
32 changes: 24 additions & 8 deletions vue-language-tools/vue-language-core/src/generators/template.ts
Expand Up @@ -47,6 +47,7 @@ const transformContext: CompilerDOM.TransformContext = {

export function generate(
ts: typeof import('typescript/lib/tsserverlibrary'),
compilerOptions: ts.CompilerOptions,
vueCompilerOptions: ResolvedVueCompilerOptions,
sourceTemplate: string,
sourceLang: string,
Expand Down Expand Up @@ -1315,14 +1316,29 @@ export function generate(
]);
codeGen.push(varSlots);
if (isStatic) {
writePropertyAccess(
slotName,
argRange,
{
...capabilitiesSet.slotName,
completion: !!prop.arg,
},
);
// https://github.com/johnsoncodehk/volar/issues/2236
if (!compilerOptions.noPropertyAccessFromIndexSignature) {
writePropertyAccess(
slotName,
argRange,
{
...capabilitiesSet.slotName,
completion: !!prop.arg,
},
);
}
else {
codeGen.push(`[`);
writeCodeWithQuotes(
slotName,
argRange,
{
...capabilitiesSet.slotName,
completion: !!prop.arg,
},
);
codeGen.push(`]`);
}
}
else {
codeGen.push(`[`);
Expand Down
Expand Up @@ -147,6 +147,7 @@ const plugin: VueLanguagePlugin = ({ modules, vueCompilerOptions, compilerOption

return templateGen.generate(
ts,
compilerOptions,
vueCompilerOptions,
_sfc.template?.content ?? '',
_sfc.template?.lang ?? 'html',
Expand Down
6 changes: 6 additions & 0 deletions vue-language-tools/vue-test-workspace/vue-tsc/#2236/main.vue
@@ -0,0 +1,6 @@
<template>
<Comp>
<template #actions></template>
<template v-slot:actions></template>
</Comp>
</template>
3 changes: 3 additions & 0 deletions vue-language-tools/vue-test-workspace/vue-tsc/tsconfig.json
@@ -1,5 +1,8 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"noPropertyAccessFromIndexSignature": true,
},
"include": [
"**/*.vue",
"**/*.html",
Expand Down

0 comments on commit 3165a08

Please sign in to comment.