The same, an empty entry kept for each hole: `[, second]` is `['', 'second']`.
(text: string)
| 1488 | |
| 1489 | /** The same, an empty entry kept for each hole: `[, second]` is `['', 'second']`. */ |
| 1490 | function 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 |
no test coverage detected