MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / topLevelItems

Function topLevelItems

src/resolution/frameworks/react.ts:1490–1511  ·  view source on GitHub ↗

The same, an empty entry kept for each hole: `[, second]` is `['', 'second']`.

(text: string)

Source from the content-addressed store, hash-verified

1488
1489/** The same, an empty entry kept for each hole: `[, second]` is `['', 'second']`. */
1490function topLevelItems(text: string): string[] {
1491 const out: string[] = [];
1492 let depth = 0;
1493 let from = 0;
1494 for (let i = 0; i < text.length; i++) {
1495 const ch = text[i]!;
1496 if (ch === '"' || ch === "'" || ch === '`') {
1497 const end = skipString(text, i);
1498 if (end < 0) break;
1499 i = end;
1500 } else if (ch === '{' || ch === '[' || ch === '(') depth++;
1501 else if (ch === '}' || ch === ']' || ch === ')') depth--;
1502 else if (ch === ',' && depth === 0) {
1503 out.push(text.slice(from, i).trim());
1504 from = i + 1;
1505 }
1506 }
1507 // A trailing comma ends a list without adding a hole.
1508 const last = text.slice(from).trim();
1509 if (last) out.push(last);
1510 return out;
1511}
1512
1513// =============================================================================
1514// What a data router's `lazy` loader renders

Callers 6

wrappedNameFunction · 0.70
loaderOfFunction · 0.70
topLevelEntriesFunction · 0.70
loaderValueFunction · 0.70
valueOfFunction · 0.70
bindPatternFunction · 0.70

Calls 2

skipStringFunction · 0.90
pushMethod · 0.80

Tested by

no test coverage detected