( absPath: string, language: Language, sites: readonly CallSite[] )
| 271 | * map otherwise, never a wrong label. |
| 272 | */ |
| 273 | export function guardsForFileSync( |
| 274 | absPath: string, |
| 275 | language: Language, |
| 276 | sites: readonly CallSite[] |
| 277 | ): Map<string, BranchGuard[]> { |
| 278 | const out = new Map<string, BranchGuard[]>(); |
| 279 | if (!supportsBranchGuards(language) || sites.length === 0) return out; |
| 280 | let stat: fs.Stats; |
| 281 | try { |
| 282 | stat = fs.statSync(absPath); |
| 283 | } catch { |
| 284 | return out; |
| 285 | } |
| 286 | const key = `${language}:${stat.mtimeMs}:${stat.size}`; |
| 287 | let cached = treeCache.get(absPath); |
| 288 | if (!cached || cached.key !== key) { |
| 289 | if (stat.size > MAX_PARSE_BYTES) return out; |
| 290 | const parser = getParser(language); |
| 291 | if (!parser) return out; |
| 292 | let source: string; |
| 293 | try { |
| 294 | source = fs.readFileSync(absPath, 'utf8'); |
| 295 | } catch { |
| 296 | return out; |
| 297 | } |
| 298 | const tree = parseWithinBudget(parser, source); |
| 299 | if (!tree) return out; |
| 300 | cached = { key, tree, source }; |
| 301 | remember(absPath, cached); |
| 302 | } |
| 303 | for (const site of sites) { |
| 304 | const k = siteKey(site); |
| 305 | if (!out.has(k)) out.set(k, guardsInTree(cached.tree.rootNode, cached.source, language, site.line, site.column ?? null)); |
| 306 | } |
| 307 | return out; |
| 308 | } |
| 309 | |
| 310 | /** The languages with rules here — what {@link warmBranchGuardGrammars} loads. */ |
| 311 | export const BRANCH_GUARD_LANGUAGES: readonly Language[] = [ |
no test coverage detected