From 4d7d8bf7a0e984ef70262b1a52950cf2e6e64a60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=B1=E5=90=B9=E8=89=B2=E5=BE=A1=E5=AE=88?= <85992002+KazariEX@users.noreply.github.com> Date: Mon, 4 Nov 2024 18:39:48 +0800 Subject: [PATCH] fix(language-core): always report missing props on `` (#4982) Co-authored-by: Johnson Chu --- packages/language-core/lib/codegen/template/element.ts | 8 ++++---- .../language-core/lib/codegen/template/elementProps.ts | 9 +++++---- .../language-core/lib/codegen/template/slotOutlet.ts | 4 ++-- test-workspace/tsc/passedFixtures/vue3/#4979/main.vue | 10 ++++++++++ 4 files changed, 21 insertions(+), 10 deletions(-) create mode 100644 test-workspace/tsc/passedFixtures/vue3/#4979/main.vue diff --git a/packages/language-core/lib/codegen/template/element.ts b/packages/language-core/lib/codegen/template/element.ts index bcc253aa5d..ec9c86def8 100644 --- a/packages/language-core/lib/codegen/template/element.ts +++ b/packages/language-core/lib/codegen/template/element.ts @@ -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, @@ -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}`; @@ -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}`; @@ -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}`; diff --git a/packages/language-core/lib/codegen/template/elementProps.ts b/packages/language-core/lib/codegen/template/elementProps.ts index 66ff31cc33..74512d60f8 100644 --- a/packages/language-core/lib/codegen/template/elementProps.ts +++ b/packages/language-core/lib/codegen/template/elementProps.ts @@ -25,6 +25,7 @@ export function* generateElementProps( ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, props: CompilerDOM.ElementNode['props'], + strictPropsCheck: boolean, enableCodeFeatures: boolean, failedPropExps?: FailedPropExpression[] ): Generator { @@ -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, @@ -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, @@ -249,8 +250,8 @@ export function* generateElementProps( } function getPropsCodeInfo( - options: TemplateCodegenOptions, ctx: TemplateCodegenContext, + strictPropsCheck: boolean, shouldCamelize: boolean ): VueCodeInformation { const codeInfo = ctx.codeFeatures.withoutHighlightAndCompletion; @@ -262,7 +263,7 @@ function getPropsCodeInfo( resolveRenameEditText: shouldCamelize ? hyphenateAttr : undefined, } : false, - verification: options.vueCompilerOptions.strictTemplates + verification: strictPropsCheck ? codeInfo.verification : { shouldReport(_source, code) { diff --git a/packages/language-core/lib/codegen/template/slotOutlet.ts b/packages/language-core/lib/codegen/template/slotOutlet.ts index 632ffc056e..ec9241911f 100644 --- a/packages/language-core/lib/codegen/template/slotOutlet.ts +++ b/packages/language-core/lib/codegen/template/slotOutlet.ts @@ -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 ( diff --git a/test-workspace/tsc/passedFixtures/vue3/#4979/main.vue b/test-workspace/tsc/passedFixtures/vue3/#4979/main.vue new file mode 100644 index 0000000000..5a07cebbaf --- /dev/null +++ b/test-workspace/tsc/passedFixtures/vue3/#4979/main.vue @@ -0,0 +1,10 @@ + + +