()
| 13 | let idCounter = 0; |
| 14 | |
| 15 | export function createRoot() { |
| 16 | const container: Container = { |
| 17 | rootID: idCounter++, |
| 18 | children: [] |
| 19 | }; |
| 20 | |
| 21 | // @ts-ignore |
| 22 | const root = createContainer(container); |
| 23 | |
| 24 | function getChildren(parent: Container | Instance) { |
| 25 | if (parent) { |
| 26 | return parent.children; |
| 27 | } |
| 28 | return null; |
| 29 | } |
| 30 | |
| 31 | function getChildrenAsJSX(root: Container) { |
| 32 | const children = childToJSX(getChildren(root)); |
| 33 | if (Array.isArray(children)) { |
| 34 | return { |
| 35 | $$typeof: REACT_ELEMENT_TYPE, |
| 36 | type: REACT_FRAGMENT_TYPE, |
| 37 | key: null, |
| 38 | ref: null, |
| 39 | props: { children }, |
| 40 | __mark: 'KaSong' |
| 41 | }; |
| 42 | } |
| 43 | return children; |
| 44 | } |
| 45 | |
| 46 | function childToJSX(child: any): any { |
| 47 | if (typeof child === 'string' || typeof child === 'number') { |
| 48 | return child; |
| 49 | } |
| 50 | |
| 51 | if (Array.isArray(child)) { |
| 52 | if (child.length === 0) { |
| 53 | return null; |
| 54 | } |
| 55 | if (child.length === 1) { |
| 56 | return childToJSX(child[0]); |
| 57 | } |
| 58 | const children = child.map(childToJSX); |
| 59 | |
| 60 | if ( |
| 61 | children.every( |
| 62 | (child) => typeof child === 'string' || typeof child === 'number' |
| 63 | ) |
| 64 | ) { |
| 65 | return children.join(''); |
| 66 | } |
| 67 | // [TextInstance, TextInstance, Instance] |
| 68 | return children; |
| 69 | } |
| 70 | |
| 71 | // Instance |
| 72 | if (Array.isArray(child.children)) { |
nothing calls this directly
no test coverage detected