Skip to content

Commit

Permalink
fix(compiler-sfc): deconstruction props error repair (vuejs#8017)
Browse files Browse the repository at this point in the history
  • Loading branch information
baiwusanyu-c committed Apr 4, 2023
1 parent 9a09e47 commit 7eddd22
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/compiler-sfc/src/compileScriptPropsDestructure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export function transformDestructuredProps(
const scopeStack: Scope[] = [rootScope]
let currentScope: Scope = rootScope
const excludedIds = new WeakSet<Identifier>()
const propsIds = new Set<string>()
const parentStack: Node[] = []
const propsLocalToPublicMap: Record<string, string> = Object.create(null)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.`,
Expand Down

0 comments on commit 7eddd22

Please sign in to comment.