(node: any)
| 22 | }; |
| 23 | |
| 24 | const parseNode = (node: any): SparseNode => { |
| 25 | const children = (node.children ?? []).map(parseNode).filter(Boolean); |
| 26 | |
| 27 | switch (node.type) { |
| 28 | case 'JSXElement': |
| 29 | return { |
| 30 | __composify__: true, |
| 31 | type: node.openingElement.name.name, |
| 32 | props: node.openingElement.attributes.reduce((properties: Record<string, any>, attribute: any) => { |
| 33 | const key = attribute.name.name; |
| 34 | const value = parseAttribute(attribute.value); |
| 35 | |
| 36 | if (value === undefined) { |
| 37 | return properties; |
| 38 | } |
| 39 | |
| 40 | properties[key] = value; |
| 41 | |
| 42 | return properties; |
| 43 | }, {}), |
| 44 | children, |
| 45 | }; |
| 46 | case 'JSXFragment': |
| 47 | return { |
| 48 | __composify__: true, |
| 49 | type: 'Fragment', |
| 50 | props: {}, |
| 51 | children, |
| 52 | }; |
| 53 | case 'JSXText': |
| 54 | return node.value.trim(); |
| 55 | default: |
| 56 | throw new SyntaxError(`${node.type} is not supported`); |
| 57 | } |
| 58 | }; |
| 59 | |
| 60 | const parseAttribute = (expression: any): any => { |
| 61 | if (expression === null) { |
no test coverage detected