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