| 111 | * template with holes, so such a matcher reads as `[]`, never as `'all'`. |
| 112 | */ |
| 113 | export function readProxyMatcher(safe: string): ProxyMatcherEntry[] | 'all' { |
| 114 | const decl = /\bexport\s+const\s+config\b[^=;]*=\s*/.exec(safe); |
| 115 | if (!decl) return 'all'; |
| 116 | const open = decl.index + decl[0].length; |
| 117 | const close = safe[open] === '{' ? matchBracket(safe, open) : -1; |
| 118 | if (close < 0) return []; |
| 119 | const field = readFields(safe, open, close).get('matcher'); |
| 120 | // A shorthand or a quoted key is a matcher this can't see into. |
| 121 | if (!field) return /\bmatcher\b/.test(safe.slice(open, close)) ? [] : 'all'; |
| 122 | const at = valueAfterKey(safe, field.at); |
| 123 | if (safe[at] !== '[') { |
| 124 | const one = stringEntry(safe, at); |
| 125 | return one ? [one] : []; |
| 126 | } |
| 127 | const end = matchBracket(safe, at); |
| 128 | const entries: ProxyMatcherEntry[] = []; |
| 129 | for (let i = at + 1; i > 0 && i < end; ) { |
| 130 | const ch = safe[i]!; |
| 131 | if (/[\s,]/.test(ch)) { |
| 132 | i++; |
| 133 | continue; |
| 134 | } |
| 135 | const entry = ch === '{' ? sourceEntry(safe, i) : stringEntry(safe, i); |
| 136 | if (!entry) return []; |
| 137 | entries.push(entry); |
| 138 | i = afterElement(safe, i, end); |
| 139 | } |
| 140 | return entries; |
| 141 | } |
| 142 | |
| 143 | function sourceEntry(s: string, open: number): ProxyMatcherEntry | null { |
| 144 | const source = readFields(s, open, matchBracket(s, open)).get('source'); |