MCPcopy Create free account
hub / github.com/donghaxkim/react-rewrite / getElementTextNormalized

Function getElementTextNormalized

packages/cli/src/transform.ts:742–759  ·  view source on GitHub ↗

* Get the normalized text content of a JSX element recursively.

(node: any)

Source from the content-addressed store, hash-verified

740 * Get the normalized text content of a JSX element recursively.
741 */
742function getElementTextNormalized(node: any): string {
743 let text = "";
744 const children = node.children;
745 if (!children) return text;
746 for (const child of children) {
747 if (child.type === "JSXText") {
748 text += normalizeWs(child.value);
749 } else if (child.type === "JSXElement") {
750 text += getElementTextNormalized(child);
751 } else if (child.type === "JSXExpressionContainer") {
752 const expr = child.expression;
753 if (expr?.type === "StringLiteral" || expr?.type === "Literal") {
754 text += String(expr.value ?? "");
755 }
756 }
757 }
758 return text;
759}
760
761function getLineStarts(source: string): number[] {
762 const starts = [0];

Callers

nothing calls this directly

Calls 1

normalizeWsFunction · 0.70

Tested by

no test coverage detected