Where a docstring after line `after` ends, or `after` without one.
(lines: readonly string[], after: number)
| 65 | |
| 66 | /** Where a docstring after line `after` ends, or `after` without one. */ |
| 67 | function docstringEnd(lines: readonly string[], after: number): number { |
| 68 | const at = lines.findIndex((line, index) => index > after && line.trim()); |
| 69 | const match = at >= 0 ? /^[rubRUB]{0,2}("""|''')/.exec(lines[at].trim()) : null; |
| 70 | if (!match) return after; |
| 71 | const rest = lines[at].trim().slice(match[0].length); |
| 72 | if (rest.includes(match[1])) return at; |
| 73 | const close = lines.findIndex((line, index) => index > at && line.includes(match[1])); |
| 74 | return close >= 0 ? close : lines.length - 1; |
| 75 | } |
| 76 | |
| 77 | function pythonFacts(lines: readonly string[], name?: string): CodeFacts | undefined { |
| 78 | const definition = new RegExp(`^\\s*(?:async\\s+)?(?:def|class)\\s+${name ? `${escape(name)}\\b` : '\\w'}`); |