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

Function updateTextContent

packages/cli/src/transform.ts:1576–1595  ·  view source on GitHub ↗
(
  filePath: string,
  lineNumber: number,
  columnNumber: number,
  originalText: string,
  newText: string,
  cursorOffset?: number,
  textAnchor?: TextEditAnchor,
)

Source from the content-addressed store, hash-verified

1574 * Returns the new source string, or null if no matching text child was found.
1575 */
1576export function updateTextContent(
1577 filePath: string,
1578 lineNumber: number,
1579 columnNumber: number,
1580 originalText: string,
1581 newText: string,
1582 cursorOffset?: number,
1583 textAnchor?: TextEditAnchor,
1584): string | null {
1585 const source = fs.readFileSync(filePath, "utf-8");
1586 const { j, root, quoteStyle } = parseSource(source, filePath);
1587
1588 const target = findJSXElementAt(j, root, lineNumber, columnNumber);
1589 if (!target) return null;
1590
1591 if (mutateTextContent(target, originalText, newText, source, cursorOffset, textAnchor)) {
1592 return root.toSource({ quote: quoteStyle });
1593 }
1594 return null;
1595}

Callers 2

applyTextEditFunction · 0.85

Calls 3

parseSourceFunction · 0.85
findJSXElementAtFunction · 0.85
mutateTextContentFunction · 0.85

Tested by 1

applyTextEditFunction · 0.68