Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions packages/runtime-core/src/componentProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,15 @@ const normalizationMap = new WeakMap<
NormalizedPropsOptions
>()

function validatePropName(key: string) {
if (key[0] !== '$') {
return true
} else if (__DEV__) {
warn(`Invalid prop name: "${key}" is a reserved property.`)
}
return false
}

function normalizePropsOptions(
raw: ComponentPropsOptions | void
): NormalizedPropsOptions {
Expand All @@ -240,10 +249,8 @@ function normalizePropsOptions(
warn(`props must be strings when using array syntax.`, raw[i])
}
const normalizedKey = camelize(raw[i])
if (normalizedKey[0] !== '$') {
if (validatePropName(normalizedKey)) {
options[normalizedKey] = EMPTY_OBJ
} else if (__DEV__) {
warn(`Invalid prop name: "${normalizedKey}" is a reserved property.`)
}
}
} else {
Expand All @@ -252,7 +259,7 @@ function normalizePropsOptions(
}
for (const key in raw) {
const normalizedKey = camelize(key)
if (normalizedKey[0] !== '$') {
if (validatePropName(normalizedKey)) {
const opt = raw[key]
const prop: NormalizedProp = (options[normalizedKey] =
isArray(opt) || isFunction(opt) ? { type: opt } : opt)
Expand All @@ -266,8 +273,6 @@ function normalizePropsOptions(
needCastKeys.push(normalizedKey)
}
}
} else if (__DEV__) {
warn(`Invalid prop name: "${normalizedKey}" is a reserved property.`)
}
}
}
Expand Down