Skip to content

Commit 7dee578

Browse files
committed
Further performance improvements
1 parent 3f37cf7 commit 7dee578

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

packages/runtime-core/src/componentProps.ts

+19-15
Original file line numberDiff line numberDiff line change
@@ -563,26 +563,30 @@ export function normalizePropsOptions(
563563
const prop: NormalizedProp = (normalized[normalizedKey] =
564564
isArray(opt) || isFunction(opt) ? { type: opt } : extend({}, opt))
565565
const propType = prop.type
566+
let shouldCast = false
566567
let shouldCastTrue = true
567568

568-
const checkForBoolean = (
569-
type: PropConstructor | true | null | undefined,
570-
) => {
571-
const typeName = isFunction(type) && type.name
572-
573-
// If we find `String` before `Boolean`, e.g. `[String, Boolean]`, we need to handle the casting slightly
574-
// differently. Props passed as `<Comp checked="">` or `<Comp checked="checked">` will either be treated as
575-
// strings or converted to a boolean `true`, depending on the order of the types.
576-
if (typeName === 'String') {
577-
shouldCastTrue = false
569+
if (isArray(propType)) {
570+
for (let index = 0; index < propType.length; ++index) {
571+
const type = propType[index]
572+
const typeName = isFunction(type) && type.name
573+
574+
if (typeName === 'Boolean') {
575+
shouldCast = true
576+
break
577+
} else if (typeName === 'String') {
578+
// If we find `String` before `Boolean`, e.g. `[String, Boolean]`,
579+
// we need to handle the casting slightly differently. Props
580+
// passed as `<Comp checked="">` or `<Comp checked="checked">`
581+
// will either be treated as strings or converted to a boolean
582+
// `true`, depending on the order of the types.
583+
shouldCastTrue = false
584+
}
578585
}
579-
580-
return typeName === 'Boolean'
586+
} else {
587+
shouldCast = isFunction(propType) && propType.name === 'Boolean'
581588
}
582589

583-
const shouldCast = isArray(propType)
584-
? propType.some(checkForBoolean)
585-
: checkForBoolean(propType)
586590
prop[BooleanFlags.shouldCast] = shouldCast
587591
prop[BooleanFlags.shouldCastTrue] = shouldCastTrue
588592
// if the prop needs boolean casting or default value

0 commit comments

Comments
 (0)