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

Function topLevelItems

src/resolution/frameworks/react.ts:1512–1533  ·  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

1510
1511/** The same, an empty entry kept for each hole: `[, second]` is `['', 'second']`. */
1512function topLevelItems(text: string): string[] {
1513 const out: string[] = [];
1514 let depth = 0;
1515 let from = 0;
1516 for (let i = 0; i < text.length; i++) {
1517 const ch = text[i]!;
1518 if (ch === '"' || ch === "'" || ch === '`') {
1519 const end = skipString(text, i);
1520 if (end < 0) break;
1521 i = end;
1522 } else if (ch === '{' || ch === '[' || ch === '(') depth++;
1523 else if (ch === '}' || ch === ']' || ch === ')') depth--;
1524 else if (ch === ',' && depth === 0) {
1525 out.push(text.slice(from, i).trim());
1526 from = i + 1;
1527 }
1528 }
1529 // A trailing comma ends a list without adding a hole.
1530 const last = text.slice(from).trim();
1531 if (last) out.push(last);
1532 return out;
1533}
1534
1535// =============================================================================
1536// 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