diff --git a/packages/runtime-core/src/componentProps.ts b/packages/runtime-core/src/componentProps.ts index b8e9bf66db5..6468825cc66 100644 --- a/packages/runtime-core/src/componentProps.ts +++ b/packages/runtime-core/src/componentProps.ts @@ -594,19 +594,26 @@ function validatePropName(key: string) { return false } +const typeMap = new WeakMap() + // use function string name to check type constructors // so that it works across vms / iframes. -function getType(ctor: Prop): string { +function getType(ctor: PropConstructor): string { + if (typeMap.has(ctor)) { + return typeMap.get(ctor)! + } const match = ctor && ctor.toString().match(/^\s*(function|class) (\w+)/) - return match ? match[2] : ctor === null ? 'null' : '' + const type = match ? match[2] : ctor === null ? 'null' : '' + if (match) typeMap.set(ctor, type) + return type } -function isSameType(a: Prop, b: Prop): boolean { +function isSameType(a: PropConstructor, b: PropConstructor): boolean { return getType(a) === getType(b) } function getTypeIndex( - type: Prop, + type: PropConstructor, expectedTypes: PropType | void | null | true ): number { if (isArray(expectedTypes)) {