Skip to content

Commit

Permalink
fix(language-core): always report missing props on <slot> (#4982)
Browse files Browse the repository at this point in the history
Co-authored-by: Johnson Chu <[email protected]>
  • Loading branch information
KazariEX and johnsoncodehk authored Nov 4, 2024
1 parent 00f6df5 commit 4d7d8bf
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
8 changes: 4 additions & 4 deletions packages/language-core/lib/codegen/template/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function* generateComponent(
yield `// @ts-ignore${newLine}`; // #2304
yield `/** @type { [`;
for (const tagOffset of tagOffsets) {
yield `typeof `
yield `typeof `;
if (var_originalComponent === node.tag) {
yield [
var_originalComponent,
Expand Down Expand Up @@ -201,7 +201,7 @@ export function* generateComponent(

yield `// @ts-ignore${newLine}`;
yield `const ${var_functionalComponent} = __VLS_asFunctionalComponent(${var_originalComponent}, new ${var_originalComponent}({`;
yield* generateElementProps(options, ctx, node, props, false);
yield* generateElementProps(options, ctx, node, props, options.vueCompilerOptions.strictTemplates, false);
yield `}))${endOfLine}`;

yield `const ${var_componentInstance} = ${var_functionalComponent}`;
Expand All @@ -212,7 +212,7 @@ export function* generateComponent(
startTagOffset + node.tag.length,
ctx.codeFeatures.verification,
`{`,
...generateElementProps(options, ctx, node, props, true, failedPropExps),
...generateElementProps(options, ctx, node, props, options.vueCompilerOptions.strictTemplates, true, failedPropExps),
`}`
);
yield `, ...__VLS_functionalComponentArgsRest(${var_functionalComponent}))${endOfLine}`;
Expand Down Expand Up @@ -315,7 +315,7 @@ export function* generateElement(
startTagOffset + node.tag.length,
ctx.codeFeatures.verification,
`{`,
...generateElementProps(options, ctx, node, node.props, true, failedPropExps),
...generateElementProps(options, ctx, node, node.props, options.vueCompilerOptions.strictTemplates, true, failedPropExps),
`}`
);
yield `)${endOfLine}`;
Expand Down
9 changes: 5 additions & 4 deletions packages/language-core/lib/codegen/template/elementProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export function* generateElementProps(
ctx: TemplateCodegenContext,
node: CompilerDOM.ElementNode,
props: CompilerDOM.ElementNode['props'],
strictPropsCheck: boolean,
enableCodeFeatures: boolean,
failedPropExps?: FailedPropExpression[]
): Generator<Code> {
Expand Down Expand Up @@ -112,7 +113,7 @@ export function* generateElementProps(
if (shouldSpread) {
yield `...{ `;
}
const codeInfo = getPropsCodeInfo(options, ctx, shouldCamelize);
const codeInfo = getPropsCodeInfo(ctx, strictPropsCheck, shouldCamelize);
const codes = wrapWith(
prop.loc.start.offset,
prop.loc.end.offset,
Expand Down Expand Up @@ -179,7 +180,7 @@ export function* generateElementProps(
if (shouldSpread) {
yield `...{ `;
}
const codeInfo = getPropsCodeInfo(options, ctx, true);
const codeInfo = getPropsCodeInfo(ctx, strictPropsCheck, true);
const codes = conditionWrapWith(
enableCodeFeatures,
prop.loc.start.offset,
Expand Down Expand Up @@ -249,8 +250,8 @@ export function* generateElementProps(
}

function getPropsCodeInfo(
options: TemplateCodegenOptions,
ctx: TemplateCodegenContext,
strictPropsCheck: boolean,
shouldCamelize: boolean
): VueCodeInformation {
const codeInfo = ctx.codeFeatures.withoutHighlightAndCompletion;
Expand All @@ -262,7 +263,7 @@ function getPropsCodeInfo(
resolveRenameEditText: shouldCamelize ? hyphenateAttr : undefined,
}
: false,
verification: options.vueCompilerOptions.strictTemplates
verification: strictPropsCheck
? codeInfo.verification
: {
shouldReport(_source, code) {
Expand Down
4 changes: 2 additions & 2 deletions packages/language-core/lib/codegen/template/slotOutlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ export function* generateSlotOutlet(
startTagOffset + node.tag.length,
ctx.codeFeatures.verification,
`{${newLine}`,
...generateElementProps(options, ctx, node, node.props.filter(prop => prop !== nameProp), true),
...generateElementProps(options, ctx, node, node.props.filter(prop => prop !== nameProp), true, true),
`}`
);
yield `)${endOfLine}`;
}
else {
yield `var ${varSlot} = {${newLine}`;
yield* generateElementProps(options, ctx, node, node.props.filter(prop => prop !== nameProp), true);
yield* generateElementProps(options, ctx, node, node.props.filter(prop => prop !== nameProp), options.vueCompilerOptions.strictTemplates, true);
yield `}${endOfLine}`;

if (
Expand Down
10 changes: 10 additions & 0 deletions test-workspace/tsc/passedFixtures/vue3/#4979/main.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script setup lang="ts">
defineSlots<{
default(props: { foo: string }): any;
}>();
</script>

<template>
<!-- @vue-expect-error -->
<slot bar="..."></slot>
</template>

0 comments on commit 4d7d8bf

Please sign in to comment.