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

Function getRenderedElementText

packages/cli/src/transform.ts:807–832  ·  view source on GitHub ↗
(node: any, source?: string, lineStarts?: number[])

Source from the content-addressed store, hash-verified

805}
806
807function getRenderedElementText(node: any, source?: string, lineStarts?: number[]): string {
808 const children = node.children;
809 if (!children) return "";
810
811 let text = "";
812 let previousChild: any | null = null;
813 let previousText = "";
814
815 for (const child of children) {
816 const childText = getRenderedChildText(child, source, lineStarts);
817 if (!childText) continue;
818
819 if (previousChild) {
820 const sourceBetween = getSourceBetween(previousChild, child, source, lineStarts);
821 if (needsBoundarySpace(previousText, childText, sourceBetween)) {
822 text += " ";
823 }
824 }
825
826 text += childText;
827 previousChild = child;
828 previousText = childText;
829 }
830
831 return collapseRenderedWhitespace(text);
832}
833
834function prependToChildText(child: any, text: string): boolean {
835 if (child.type === "JSXText") {

Callers 2

mutateTextContentFunction · 0.85
getRenderedChildTextFunction · 0.85

Calls 4

getRenderedChildTextFunction · 0.85
getSourceBetweenFunction · 0.85
needsBoundarySpaceFunction · 0.85

Tested by

no test coverage detected