* Whether the `{` or `[` at `opener` opens a pattern that binds its names: a * declaration's, unless it declares an import, or a parameter's — itself or * through the patterns it nests in.
(code: string, opener: number, depth: number)
| 2466 | * through the patterns it nests in. |
| 2467 | */ |
| 2468 | function bindsPattern(code: string, opener: number, depth: number): boolean { |
| 2469 | if (depth > 8) return false; |
| 2470 | const p = skipSpace(code, opener - 1, -1); |
| 2471 | const c = code[p]; |
| 2472 | if (c === '(') return opensParameters(code, p); |
| 2473 | if (c === '[') return bindsPattern(code, p, depth + 1); |
| 2474 | if (c === ',') { |
| 2475 | const q = enclosingOpener(code, p - 1); |
| 2476 | if (code[q] === '(') return opensParameters(code, q); |
| 2477 | return code[q] === '[' && bindsPattern(code, q, depth + 1); |
| 2478 | } |
| 2479 | if (c === ':') { |
| 2480 | // `{ key: { … } }` nests a pattern; `props: {` and `}: {` annotate a type. |
| 2481 | if (!keyOpensElement(code, p)) return false; |
| 2482 | const q = enclosingOpener(code, p - 1); |
| 2483 | return code[q] === '{' && bindsPattern(code, q, depth + 1); |
| 2484 | } |
| 2485 | if (!ID_CHAR.test(c ?? '')) return false; |
| 2486 | const word = wordEndingAt(code, p); |
| 2487 | if (word !== 'const' && word !== 'let' && word !== 'var') return false; |
| 2488 | const close = matchingCloser(code, opener); |
| 2489 | if (close < 0) return false; |
| 2490 | IMPORTED_VALUE.lastIndex = close + 1; |
| 2491 | return !IMPORTED_VALUE.test(code); |
| 2492 | } |
| 2493 | |
| 2494 | /** |
| 2495 | * Whether the `(` at `paren` opens a parameter list: an arrow or a body |
no test coverage detected