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

Function findPosition

packages/cli/src/__tests__/batch-transform.test.ts:25–32  ·  view source on GitHub ↗

Find line:col of an opening JSX tag in source.

(source: string, tag: string)

Source from the content-addressed store, hash-verified

23
24/** Find line:col of an opening JSX tag in source. */
25function findPosition(source: string, tag: string): { line: number; col: number } {
26 const lines = source.split("\n");
27 for (let i = 0; i < lines.length; i++) {
28 const col = lines[i].indexOf(`<${tag}`);
29 if (col !== -1) return { line: i + 1, col }; // 1-indexed line, 0-indexed col
30 }
31 throw new Error(`Tag <${tag}> not found`);
32}
33
34function findMarkdownPosition(source: string, snippet: string): { line: number; col: number } {
35 const lines = source.split("\n");

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected