Extract public method signatures from class declarations.
(text: str)
| 204 | |
| 205 | |
| 206 | def _parse_class_methods(text: str) -> dict: |
| 207 | """Extract public method signatures from class declarations.""" |
| 208 | classes = {} |
| 209 | class_pattern = re.compile( |
| 210 | r"export\s+class\s+(\w+)" |
| 211 | r"(?:<[^{]*?>)?" |
| 212 | r"(?:\s+extends\s+([\w<>,\s]+?))?" |
| 213 | r"(?:\s+implements\s+([\w<>,\s]+?))?" |
| 214 | r"\s*\{" |
| 215 | ) |
| 216 | pos = 0 |
| 217 | while pos < len(text): |
| 218 | m = class_pattern.search(text, pos) |
| 219 | if not m: |
| 220 | break |
| 221 | name = m.group(1) |
| 222 | extends = m.group(2).strip() if m.group(2) else None |
| 223 | |
| 224 | brace_start = m.end() - 1 |
| 225 | depth = 1 |
| 226 | i = brace_start + 1 |
| 227 | while i < len(text) and depth > 0: |
| 228 | if text[i] == "{": |
| 229 | depth += 1 |
| 230 | elif text[i] == "}": |
| 231 | depth -= 1 |
| 232 | i += 1 |
| 233 | body = text[brace_start + 1 : i - 1] |
| 234 | body_clean = _strip_comments(body) |
| 235 | |
| 236 | methods = {} |
| 237 | # Extract methods by finding name( and then balancing parens |
| 238 | method_start_re = re.compile(r"(?:readonly\s+)?(\w+)\s*\(") |
| 239 | pos_m = 0 |
| 240 | while pos_m < len(body_clean): |
| 241 | mm = method_start_re.search(body_clean, pos_m) |
| 242 | if not mm: |
| 243 | break |
| 244 | mname = mm.group(1) |
| 245 | if mname in ("constructor", "if", "return", "new", "throw", "console"): |
| 246 | pos_m = mm.end() |
| 247 | continue |
| 248 | # Balance parens to find end of params |
| 249 | paren_start = mm.end() - 1 |
| 250 | depth_p = 1 |
| 251 | j = paren_start + 1 |
| 252 | while j < len(body_clean) and depth_p > 0: |
| 253 | if body_clean[j] == "(": |
| 254 | depth_p += 1 |
| 255 | elif body_clean[j] == ")": |
| 256 | depth_p -= 1 |
| 257 | j += 1 |
| 258 | if depth_p != 0: |
| 259 | pos_m = mm.end() |
| 260 | continue |
| 261 | params_str = body_clean[paren_start + 1 : j - 1] |
| 262 | # Look for : return_type after the closing paren |
| 263 | rest = body_clean[j:].lstrip() |
no test coverage detected