Bind each declarator of a `const`, `let` or `var` whose first pattern starts at `at`; where the declaration ends.
(body: string, at: number, scope: Map<string, Loaded | null>)
| 1740 | |
| 1741 | /** Bind each declarator of a `const`, `let` or `var` whose first pattern starts at `at`; where the declaration ends. */ |
| 1742 | function declare(body: string, at: number, scope: Map<string, Loaded | null>): number { |
| 1743 | for (let i = at; ;) { |
| 1744 | while (/\s/.test(body[i] ?? '')) i++; |
| 1745 | let end: number; |
| 1746 | if (body[i] === '{' || body[i] === '[') end = matchBracket(body, i) + 1; |
| 1747 | else end = i + (/^[A-Za-z_$][\w$]*/.exec(body.slice(i, i + 128))?.[0].length ?? 0); |
| 1748 | if (end <= i) return Math.max(end, i + 1); |
| 1749 | const pattern = body.slice(i, end); |
| 1750 | const init = initializerAt(body, end); |
| 1751 | let stop = end; |
| 1752 | if (init < 0) bindPattern(scope, pattern, null); |
| 1753 | else { |
| 1754 | stop = statementEnd(body, init, true); |
| 1755 | bindPattern(scope, pattern, valueOf(body.slice(init, stop), scope)); |
| 1756 | } |
| 1757 | while (/\s/.test(body[stop] ?? '')) stop++; |
| 1758 | if (body[stop] !== ',') return stop; |
| 1759 | i = stop + 1; |
| 1760 | } |
| 1761 | } |
| 1762 | |
| 1763 | /** Where a declarator's initializer starts, past its `: Type` and `=`; -1 when it has none. */ |
| 1764 | export function initializerAt(body: string, at: number): number { |
no test coverage detected