The two branches of a conditional expression, `test ? yes : no`; null for any other expression.
(text: string)
| 798 | |
| 799 | /** The two branches of a conditional expression, `test ? yes : no`; null for any other expression. */ |
| 800 | function conditionalBranches(text: string): [string, string] | null { |
| 801 | let question = -1; |
| 802 | let open = 0; |
| 803 | for (let i = 0; i < text.length; i++) { |
| 804 | const ch = text[i]!; |
| 805 | if (ch === '"' || ch === "'" || ch === '`' || ch === '{' || ch === '(' || ch === '[') { |
| 806 | i = ch === '{' || ch === '(' || ch === '[' ? matchBracket(text, i) : skipString(text, i); |
| 807 | if (i < 0) return null; |
| 808 | } else if (ch === '?') { |
| 809 | // `??` and `?.` are no conditional. |
| 810 | if (text[i + 1] === '?' || (text[i + 1] === '.' && !/\d/.test(text[i + 2] ?? ''))) i++; |
| 811 | else if (open++ === 0) question = i; |
| 812 | } else if (ch === ':' && open > 0 && --open === 0) { |
| 813 | return [text.slice(question + 1, i), text.slice(i + 1)]; |
| 814 | } |
| 815 | } |
| 816 | return null; |
| 817 | } |
| 818 | |
| 819 | /** |
| 820 | * The page a lazy wrapper's loader resolves to: a module's default export, an |
no test coverage detected