* Where `name`'s table literal opens, for `const name = [ … ]` (or the tables * a function returns when `call`) — or, for `const name = getRouteMap({ … * })`, the function whose returned table the value holds. Of several * declarations of the name, the one `visible` picks.
( safe: string, name: string, call: boolean, visible: (keywords: number[]) => number | undefined )
| 2140 | * declarations of the name, the one `visible` picks. |
| 2141 | */ |
| 2142 | function declaredTable( |
| 2143 | safe: string, |
| 2144 | name: string, |
| 2145 | call: boolean, |
| 2146 | visible: (keywords: number[]) => number | undefined |
| 2147 | ): TableSite[] { |
| 2148 | const id = escapeRegExp(name); |
| 2149 | const decls = [...safe.matchAll(new RegExp(`(?:^|[^\\w$.])((?:const|let|var)\\s+${id}\\s*(?::[^=;]*)?=\\s*)`, 'g'))]; |
| 2150 | const chosen = decls.length > 0 ? visible(decls.map((d) => d.index + d[0].length - d[1]!.length)) : undefined; |
| 2151 | const decl = chosen === undefined ? undefined : decls[chosen]; |
| 2152 | if (decl) { |
| 2153 | const after = decl.index + decl[0].length; |
| 2154 | return call ? returnedTables(safe, after) : heldTable(safe, after); |
| 2155 | } |
| 2156 | if (!call) return []; |
| 2157 | const fn = new RegExp(`(?:^|[^\\w$.])function\\s+${id}\\s*\\(`).exec(safe); |
| 2158 | return fn ? returnedTables(safe, fn.index + fn[0].indexOf('function')) : []; |
| 2159 | } |
| 2160 | |
| 2161 | /** A table to read: where its literal opens in the file at hand, or a function whose returned tables to read. */ |
| 2162 | type TableSite = number | TableName; |
no test coverage detected