( immutableFormaters: Array<DevToolsFormatter>, result: unknown )
| 19 | } |
| 20 | |
| 21 | export default function normalizeResult( |
| 22 | immutableFormaters: Array<DevToolsFormatter>, |
| 23 | result: unknown |
| 24 | ): JsonMLElementList | Element { |
| 25 | const formatter = getFormatter(immutableFormaters, result); |
| 26 | |
| 27 | if (!formatter) { |
| 28 | if (Array.isArray(result) && result[0] === 'object' && result[1]?.object) { |
| 29 | // handle special case for deep objects |
| 30 | const objectFormatter = getFormatter( |
| 31 | immutableFormaters, |
| 32 | result[1].object |
| 33 | ); |
| 34 | |
| 35 | if (objectFormatter) { |
| 36 | return normalizeResult(immutableFormaters, result[1].object); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | if (typeof result !== 'string' && isElement(result)) { |
| 41 | return normalizeElement(immutableFormaters, result); |
| 42 | } |
| 43 | |
| 44 | if (typeof result === 'string') { |
| 45 | return result; |
| 46 | } |
| 47 | |
| 48 | return JSON.stringify(result); |
| 49 | } |
| 50 | |
| 51 | const header = formatter.header(result) ?? []; |
| 52 | |
| 53 | let body: JsonMLElementList | null = formatter.hasBody(result) |
| 54 | ? formatter.body(result) |
| 55 | : null; |
| 56 | |
| 57 | if (body) { |
| 58 | body = body.map((item) => normalizeElement(immutableFormaters, item)); |
| 59 | } |
| 60 | |
| 61 | if (!body) { |
| 62 | return ['span', header]; |
| 63 | } |
| 64 | |
| 65 | return ['span', header, body]; |
| 66 | } |
| 67 | |
| 68 | function normalizeElement( |
| 69 | immutableFormaters: Array<DevToolsFormatter>, |
no test coverage detected