(stripped: string, original: string, fileStartLine: number, out: BoundaryMatch[], seen: Map<string, BoundaryMatch>)
| 324 | const MAX_GETATTR_ARGS = 300; |
| 325 | |
| 326 | function scanPythonGetattr(stripped: string, original: string, fileStartLine: number, out: BoundaryMatch[], seen: Map<string, BoundaryMatch>): void { |
| 327 | GETATTR_RE.lastIndex = 0; |
| 328 | let m: RegExpExecArray | null; |
| 329 | while ((m = GETATTR_RE.exec(stripped)) !== null && out.length < MAX_MATCHES_PER_BODY) { |
| 330 | const open = m.index + m[0].length - 1; |
| 331 | const close = matchBalancedParen(stripped, open); |
| 332 | if (close === -1) continue; |
| 333 | |
| 334 | let form: string | undefined; |
| 335 | let label = ''; |
| 336 | // Immediate call: getattr(...)( |
| 337 | const after = stripped.slice(close + 1, close + 8); |
| 338 | if (/^\s*\(/.test(after)) { |
| 339 | form = 'getattr-call'; |
| 340 | label = 'getattr dispatch'; |
| 341 | } else { |
| 342 | // Assigned form: look back for `name =` and forward for `name(`. |
| 343 | const lineStart = stripped.lastIndexOf('\n', m.index) + 1; |
| 344 | const before = stripped.slice(lineStart, m.index); |
| 345 | const assign = before.match(/(\w+)\s*=\s*$/); |
| 346 | if (assign && new RegExp(`\\b${assign[1]}\\s*\\(`).test(stripped.slice(close + 1))) { |
| 347 | form = 'getattr-assign'; |
| 348 | label = 'getattr dispatch (assigned, called later)'; |
| 349 | } |
| 350 | } |
| 351 | if (!form) continue; |
| 352 | |
| 353 | const key = singleStringLiteral(original.slice(open + 1, close)); |
| 354 | const dedupeKey = `${form}|${key ?? ''}`; |
| 355 | const prior = seen.get(dedupeKey); |
| 356 | if (prior) { |
| 357 | prior.moreSites = (prior.moreSites ?? 0) + 1; |
| 358 | continue; |
| 359 | } |
| 360 | const match: BoundaryMatch = { |
| 361 | form, |
| 362 | label, |
| 363 | snippet: snippetAround(original, m.index), |
| 364 | line: fileStartLine + countNewlines(original, m.index), |
| 365 | ...(key ? { key } : {}), |
| 366 | }; |
| 367 | seen.set(dedupeKey, match); |
| 368 | out.push(match); |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | /** Index of the `)` balancing `text[open]`, or -1 (cap: MAX_GETATTR_ARGS chars). */ |
| 373 | function matchBalancedParen(text: string, open: number): number { |
no test coverage detected