File size: 1,384 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
// This regex will have fast negatives meaning valid identifiers may not pass
// this test. However this is only used during static generation to provide hints
// about why a page bailed out of some or all prerendering and we can use bracket notation
// for example while `ಠ_ಠ` is a valid identifier it's ok to print `searchParams['ಠ_ಠ']`
// even if this would have been fine too `searchParams.ಠ_ಠ`
const isDefinitelyAValidIdentifier = /^[A-Za-z_$][A-Za-z0-9_$]*$/
export function describeStringPropertyAccess(target: string, prop: string) {
if (isDefinitelyAValidIdentifier.test(prop)) {
return `\`${target}.${prop}\``
}
return `\`${target}[${JSON.stringify(prop)}]\``
}
export function describeHasCheckingStringProperty(
target: string,
prop: string
) {
const stringifiedProp = JSON.stringify(prop)
return `\`Reflect.has(${target}, ${stringifiedProp})\`, \`${stringifiedProp} in ${target}\`, or similar`
}
export const wellKnownProperties = new Set([
'hasOwnProperty',
'isPrototypeOf',
'propertyIsEnumerable',
'toString',
'valueOf',
'toLocaleString',
// Promise prototype
// fallthrough
'then',
'catch',
'finally',
// React Promise extension
// fallthrough
'status',
// React introspection
'displayName',
'_debugInfo',
// Common tested properties
// fallthrough
'toJSON',
'$$typeof',
'__esModule',
])
|