* The patterns `code` destructures at its top, as [opener, closer] pairs: a * declaration's outside every brace, so in no function, class or block, and * never a top-level callback's parameter. Braces alone are counted: JSX text * may hold a stray `(` or `[`, never a `{` that opens no expression,
(code: string)
| 2338 | * `code` (`jsxCode`) balances them. |
| 2339 | */ |
| 2340 | function topLevelPatterns(code: string): Array<[number, number]> { |
| 2341 | const patterns: Array<[number, number]> = []; |
| 2342 | let depth = 0; |
| 2343 | let at = 0; |
| 2344 | DESTRUCTURING_DECLARATION.lastIndex = 0; |
| 2345 | for (let m = DESTRUCTURING_DECLARATION.exec(code); m; m = DESTRUCTURING_DECLARATION.exec(code)) { |
| 2346 | for (; at < m.index; at++) { |
| 2347 | if (code[at] === '{') depth++; |
| 2348 | else if (code[at] === '}') depth--; |
| 2349 | } |
| 2350 | if (depth !== 0) continue; |
| 2351 | const open = m.index + m[0].length - 1; |
| 2352 | const close = matchingCloser(code, open); |
| 2353 | if (close > open) patterns.push([open, close]); |
| 2354 | } |
| 2355 | return patterns; |
| 2356 | } |
| 2357 | |
| 2358 | /** |
| 2359 | * Whether one of `patterns` in `code` binds `name` (`bindingElementAt`), so |
no test coverage detected