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

Function containsText

packages/cli/src/batch-transform.ts:230–240  ·  view source on GitHub ↗

Check if a JSX element's text content (recursive) contains the given text. * Uses whitespace-normalized comparison because React collapses JSX whitespace * (newlines → spaces) but the AST retains raw formatting.

(node: any, text: string)

Source from the content-addressed store, hash-verified

228 * Uses whitespace-normalized comparison because React collapses JSX whitespace
229 * (newlines → spaces) but the AST retains raw formatting. */
230function containsText(node: any, text: string): boolean {
231 const normalized = normalizeWs(text.trim());
232 if (!normalized) return false;
233 const children = node.children;
234 if (!children) return false;
235 for (const child of children) {
236 if (child.type === "JSXText" && normalizeWs(child.value.trim()).includes(normalized)) return true;
237 if (child.type === "JSXElement" && containsText(child, text)) return true;
238 }
239 return false;
240}
241
242// ── Node resolution ──────────────────────────────────────────────────────
243

Callers 1

resolveNodesFunction · 0.85

Calls 1

normalizeWsFunction · 0.70

Tested by

no test coverage detected