| 1 |
import { |
| 2 |
isJSXText, |
| 3 |
isJSXExpressionContainer, |
| 4 |
isJSXEmptyExpression, |
| 5 |
} from "../../validators/generated"; |
| 6 |
import cleanJSXElementLiteralChild from "../../utils/react/cleanJSXElementLiteralChild"; |
| 7 |
import type * as t from "../.."; |
| 8 |
|
| 9 |
type ReturnedChild = |
| 10 |
| t.JSXSpreadChild |
| 11 |
| t.JSXElement |
| 12 |
| t.JSXFragment |
| 13 |
| t.Expression; |
| 14 |
|
| 15 |
export default function buildChildren( |
| 16 |
node: t.JSXElement | t.JSXFragment, |
| 17 |
): ReturnedChild[] { |
| 18 |
const elements = []; |
| 19 |
|
| 20 |
for (let i = 0; i < node.children.length; i++) { |
| 21 |
let child: any = node.children[i]; |
| 22 |
|
| 23 |
if (isJSXText(child)) { |
| 24 |
cleanJSXElementLiteralChild(child, elements); |
| 25 |
continue; |
| 26 |
} |
| 27 |
|
| 28 |
if (isJSXExpressionContainer(child)) child = child.expression; |
| 29 |
if (isJSXEmptyExpression(child)) continue; |
| 30 |
|
| 31 |
elements.push(child); |
| 32 |
} |
| 33 |
|
| 34 |
return elements; |
| 35 |
} |