( propertyName: string, value: mixed, properties: Array<[string, string]>, indent: number, prefix: string, )
| 64 | } |
| 65 | |
| 66 | export function addValueToProperties( |
| 67 | propertyName: string, |
| 68 | value: mixed, |
| 69 | properties: Array<[string, string]>, |
| 70 | indent: number, |
| 71 | prefix: string, |
| 72 | ): void { |
| 73 | let desc; |
| 74 | switch (typeof value) { |
| 75 | case 'object': |
| 76 | if (value === null) { |
| 77 | desc = 'null'; |
| 78 | break; |
| 79 | } else { |
| 80 | if (value.$$typeof === REACT_ELEMENT_TYPE) { |
| 81 | // JSX |
| 82 | const typeName = getComponentNameFromType(value.type) || '\u2026'; |
| 83 | const key = value.key; |
| 84 | const props: any = value.props; |
| 85 | const propsKeys = Object.keys(props); |
| 86 | const propsLength = propsKeys.length; |
| 87 | if (key == null && propsLength === 0) { |
| 88 | desc = '<' + typeName + ' />'; |
| 89 | break; |
| 90 | } |
| 91 | if ( |
| 92 | indent < 3 || |
| 93 | (propsLength === 1 && propsKeys[0] === 'children' && key == null) |
| 94 | ) { |
| 95 | desc = '<' + typeName + ' \u2026 />'; |
| 96 | break; |
| 97 | } |
| 98 | properties.push([ |
| 99 | prefix + '\xa0\xa0'.repeat(indent) + propertyName, |
| 100 | '<' + typeName, |
| 101 | ]); |
| 102 | if (key !== null) { |
| 103 | addValueToProperties('key', key, properties, indent + 1, prefix); |
| 104 | } |
| 105 | let hasChildren = false; |
| 106 | for (const propKey in props) { |
| 107 | if (propKey === 'children') { |
| 108 | if ( |
| 109 | props.children != null && |
| 110 | (!isArray(props.children) || props.children.length > 0) |
| 111 | ) { |
| 112 | hasChildren = true; |
| 113 | } |
| 114 | } else if ( |
| 115 | hasOwnProperty.call(props, propKey) && |
| 116 | propKey[0] !== '_' |
| 117 | ) { |
| 118 | addValueToProperties( |
| 119 | propKey, |
| 120 | props[propKey], |
| 121 | properties, |
| 122 | indent + 1, |
| 123 | prefix, |
no test coverage detected