| 1574 | * Returns the new source string, or null if no matching text child was found. |
| 1575 | */ |
| 1576 | export 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 | } |