From 7eddd225d78b96ed8546c377fa5920cce40c2fe3 Mon Sep 17 00:00:00 2001 From: baiwusanyu-c <740132583@qq.com> Date: Tue, 4 Apr 2023 13:48:48 +0800 Subject: [PATCH] fix(compiler-sfc): deconstruction props error repair (#8017) --- packages/compiler-sfc/src/compileScriptPropsDestructure.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/compiler-sfc/src/compileScriptPropsDestructure.ts b/packages/compiler-sfc/src/compileScriptPropsDestructure.ts index 4ee09070d76..24a8345c5fb 100644 --- a/packages/compiler-sfc/src/compileScriptPropsDestructure.ts +++ b/packages/compiler-sfc/src/compileScriptPropsDestructure.ts @@ -38,6 +38,7 @@ export function transformDestructuredProps( const scopeStack: Scope[] = [rootScope] let currentScope: Scope = rootScope const excludedIds = new WeakSet() + const propsIds = new Set() const parentStack: Node[] = [] const propsLocalToPublicMap: Record = Object.create(null) @@ -100,6 +101,7 @@ export function transformDestructuredProps( if (isDefineProps) { // for defineProps destructure, only exclude them since they // are already passed in as knownProps + propsIds.add(id.name) excludedIds.add(id) } else { registerLocalBinding(id) @@ -155,7 +157,7 @@ export function transformDestructuredProps( function checkUsage(node: Node, method: string, alias = method) { if (isCallOf(node, alias)) { const arg = unwrapTSNode(node.arguments[0]) - if (arg.type === 'Identifier') { + if (arg.type === 'Identifier' && propsIds.has(arg.name)) { error( `"${arg.name}" is a destructured prop and should not be passed directly to ${method}(). ` + `Pass a getter () => ${arg.name} instead.`,