Skip to content
Closed
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
15 changes: 11 additions & 4 deletions packages/runtime-core/src/componentProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -594,19 +594,26 @@ function validatePropName(key: string) {
return false
}

const typeMap = new WeakMap<PropConstructor, string>()

// use function string name to check type constructors
// so that it works across vms / iframes.
function getType(ctor: Prop<any>): 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<any>, b: Prop<any>): boolean {
function isSameType(a: PropConstructor, b: PropConstructor): boolean {
return getType(a) === getType(b)
}

function getTypeIndex(
type: Prop<any>,
type: PropConstructor,
expectedTypes: PropType<any> | void | null | true
): number {
if (isArray(expectedTypes)) {
Expand Down