Skip to content

Commit

Permalink
fix: accessing an unknown slot name does not report an error
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed May 3, 2023
1 parent a082907 commit 4f7f872
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions packages/vue-language-core/src/generators/template.ts
Expand Up @@ -730,6 +730,7 @@ export function generate(
}
}
codes.push(
['', 'template', (slotDir.arg ?? slotDir).loc.start.offset, capabilitiesPresets.diagnosticOnly],
`${componentCtxVar}.slots!`,
...(
(slotDir?.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && slotDir.arg.content)
Expand All @@ -739,8 +740,14 @@ export function generate(
slotDir.arg.loc.start.offset,
slotDir.arg.isStatic ? capabilitiesPresets.slotName : capabilitiesPresets.all
], slotDir.arg.loc)
: ['.default']
: createPropertyAccessCode([
'default',
'template',
[slotDir.loc.start.offset, slotDir.loc.start.offset + (slotDir.loc.source.startsWith('#') ? '#'.length : slotDir.loc.source.startsWith('v-slot:') ? 'v-slot:'.length : 0)],
capabilitiesPresets.slotName,
])
),
['', 'template', (slotDir.arg ?? slotDir).loc.end.offset, capabilitiesPresets.diagnosticOnly],
);
if (hasProps) {
codes.push(')');
Expand All @@ -762,17 +769,12 @@ export function generate(
isStatic = slotDir.arg.isStatic;
}
if (isStatic && slotDir && !slotDir.arg) {
let offset = slotDir.loc.start.offset;
if (slotDir.loc.source.startsWith('#'))
offset += '#'.length;
else if (slotDir.loc.source.startsWith('v-slot:'))
offset += 'v-slot:'.length;
codes.push(
`${componentCtxVar}.slots!['`,
[
'',
'template',
offset,
slotDir.loc.start.offset + (slotDir.loc.source.startsWith('#') ? '#'.length : slotDir.loc.source.startsWith('v-slot:') ? 'v-slot:'.length : 0),
{ completion: true },
],
`'/* empty slot name completion */]\n`,
Expand Down

0 comments on commit 4f7f872

Please sign in to comment.