* Whether a `|` at `i` opens a closure's parameter list: it stands where an * expression starts — after `(`, `[`, `{`, `,`, `=`, `;`, `:`, `=>`, or * `move` / `return` / `async` — never after an operand, where it is an `|` * of bits or a pattern's alternative.
(code: string, i: number)
| 377 | * of bits or a pattern's alternative. |
| 378 | */ |
| 379 | function opensClosure(code: string, i: number): boolean { |
| 380 | let k = i - 1; |
| 381 | while (k >= 0 && /\s/.test(code[k]!)) k--; |
| 382 | if (k < 0) return true; |
| 383 | const c = code[k]!; |
| 384 | if (c === ':') return code[k - 1] !== ':'; |
| 385 | if ('([{,=;'.includes(c)) return true; |
| 386 | if (c === '>') return code[k - 1] === '='; |
| 387 | const word = /([A-Za-z_]\w*)$/.exec(code.slice(Math.max(0, k - 8), k + 1))?.[1]; |
| 388 | return word === 'move' || word === 'return' || word === 'async' || word === 'static'; |
| 389 | } |
| 390 | |
| 391 | /** Where an expression starting at `from` ends: its first top-level `,` or `;`, or the bracket closing around it. */ |
| 392 | function expressionEnd(code: string, from: number, close: Map<number, number>): number { |
no test coverage detected