Skip to content

Commit 4d7d8bf

Browse files
fix(language-core): always report missing props on <slot> (#4982)
Co-authored-by: Johnson Chu <[email protected]>
1 parent 00f6df5 commit 4d7d8bf

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

packages/language-core/lib/codegen/template/element.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export function* generateComponent(
8585
yield `// @ts-ignore${newLine}`; // #2304
8686
yield `/** @type { [`;
8787
for (const tagOffset of tagOffsets) {
88-
yield `typeof `
88+
yield `typeof `;
8989
if (var_originalComponent === node.tag) {
9090
yield [
9191
var_originalComponent,
@@ -201,7 +201,7 @@ export function* generateComponent(
201201

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

207207
yield `const ${var_componentInstance} = ${var_functionalComponent}`;
@@ -212,7 +212,7 @@ export function* generateComponent(
212212
startTagOffset + node.tag.length,
213213
ctx.codeFeatures.verification,
214214
`{`,
215-
...generateElementProps(options, ctx, node, props, true, failedPropExps),
215+
...generateElementProps(options, ctx, node, props, options.vueCompilerOptions.strictTemplates, true, failedPropExps),
216216
`}`
217217
);
218218
yield `, ...__VLS_functionalComponentArgsRest(${var_functionalComponent}))${endOfLine}`;
@@ -315,7 +315,7 @@ export function* generateElement(
315315
startTagOffset + node.tag.length,
316316
ctx.codeFeatures.verification,
317317
`{`,
318-
...generateElementProps(options, ctx, node, node.props, true, failedPropExps),
318+
...generateElementProps(options, ctx, node, node.props, options.vueCompilerOptions.strictTemplates, true, failedPropExps),
319319
`}`
320320
);
321321
yield `)${endOfLine}`;

packages/language-core/lib/codegen/template/elementProps.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export function* generateElementProps(
2525
ctx: TemplateCodegenContext,
2626
node: CompilerDOM.ElementNode,
2727
props: CompilerDOM.ElementNode['props'],
28+
strictPropsCheck: boolean,
2829
enableCodeFeatures: boolean,
2930
failedPropExps?: FailedPropExpression[]
3031
): Generator<Code> {
@@ -112,7 +113,7 @@ export function* generateElementProps(
112113
if (shouldSpread) {
113114
yield `...{ `;
114115
}
115-
const codeInfo = getPropsCodeInfo(options, ctx, shouldCamelize);
116+
const codeInfo = getPropsCodeInfo(ctx, strictPropsCheck, shouldCamelize);
116117
const codes = wrapWith(
117118
prop.loc.start.offset,
118119
prop.loc.end.offset,
@@ -179,7 +180,7 @@ export function* generateElementProps(
179180
if (shouldSpread) {
180181
yield `...{ `;
181182
}
182-
const codeInfo = getPropsCodeInfo(options, ctx, true);
183+
const codeInfo = getPropsCodeInfo(ctx, strictPropsCheck, true);
183184
const codes = conditionWrapWith(
184185
enableCodeFeatures,
185186
prop.loc.start.offset,
@@ -249,8 +250,8 @@ export function* generateElementProps(
249250
}
250251

251252
function getPropsCodeInfo(
252-
options: TemplateCodegenOptions,
253253
ctx: TemplateCodegenContext,
254+
strictPropsCheck: boolean,
254255
shouldCamelize: boolean
255256
): VueCodeInformation {
256257
const codeInfo = ctx.codeFeatures.withoutHighlightAndCompletion;
@@ -262,7 +263,7 @@ function getPropsCodeInfo(
262263
resolveRenameEditText: shouldCamelize ? hyphenateAttr : undefined,
263264
}
264265
: false,
265-
verification: options.vueCompilerOptions.strictTemplates
266+
verification: strictPropsCheck
266267
? codeInfo.verification
267268
: {
268269
shouldReport(_source, code) {

packages/language-core/lib/codegen/template/slotOutlet.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ export function* generateSlotOutlet(
5555
startTagOffset + node.tag.length,
5656
ctx.codeFeatures.verification,
5757
`{${newLine}`,
58-
...generateElementProps(options, ctx, node, node.props.filter(prop => prop !== nameProp), true),
58+
...generateElementProps(options, ctx, node, node.props.filter(prop => prop !== nameProp), true, true),
5959
`}`
6060
);
6161
yield `)${endOfLine}`;
6262
}
6363
else {
6464
yield `var ${varSlot} = {${newLine}`;
65-
yield* generateElementProps(options, ctx, node, node.props.filter(prop => prop !== nameProp), true);
65+
yield* generateElementProps(options, ctx, node, node.props.filter(prop => prop !== nameProp), options.vueCompilerOptions.strictTemplates, true);
6666
yield `}${endOfLine}`;
6767

6868
if (
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<script setup lang="ts">
2+
defineSlots<{
3+
default(props: { foo: string }): any;
4+
}>();
5+
</script>
6+
7+
<template>
8+
<!-- @vue-expect-error -->
9+
<slot bar="..."></slot>
10+
</template>

0 commit comments

Comments
 (0)