(node: Node | string)
| 152 | }; |
| 153 | |
| 154 | export const stringify = (node: Node | string): string => { |
| 155 | if (typeof node === 'string') { |
| 156 | return node; |
| 157 | } |
| 158 | |
| 159 | const attributes = stringifyAttributes(node.props); |
| 160 | const children = node.children.map((child) => stringify(child)).join(''); |
| 161 | |
| 162 | if (node.type === 'Fragment') { |
| 163 | return `<>${children}</>`; |
| 164 | } |
| 165 | |
| 166 | const attrs = attributes ? ` ${attributes}` : ''; |
| 167 | |
| 168 | if (children.length > 0) { |
| 169 | return `<${node.type}${attrs}>${children}</${node.type}>`; |
| 170 | } |
| 171 | |
| 172 | return `<${node.type}${attrs} />`; |
| 173 | }; |
| 174 | |
| 175 | const stringifyAttributes = (props: Record<string, unknown>): string => { |
| 176 | return Object.entries(props) |
no test coverage detected