Extract interfaces with extends chains and property declarations.
(text: str)
| 25 | |
| 26 | |
| 27 | def _parse_interfaces(text: str) -> dict: |
| 28 | """Extract interfaces with extends chains and property declarations.""" |
| 29 | interfaces = {} |
| 30 | pattern = re.compile( |
| 31 | r"(?:export\s+)?interface\s+(\w+)" |
| 32 | r"(?:\s+extends\s+([\w\s,<>]+?))?" |
| 33 | r"\s*\{" |
| 34 | ) |
| 35 | pos = 0 |
| 36 | while pos < len(text): |
| 37 | m = pattern.search(text, pos) |
| 38 | if not m: |
| 39 | break |
| 40 | name = m.group(1) |
| 41 | extends_raw = m.group(2) or "" |
| 42 | extends = [e.strip() for e in extends_raw.split(",") if e.strip()] |
| 43 | |
| 44 | brace_start = m.end() - 1 |
| 45 | depth = 1 |
| 46 | i = brace_start + 1 |
| 47 | while i < len(text) and depth > 0: |
| 48 | if text[i] == "{": |
| 49 | depth += 1 |
| 50 | elif text[i] == "}": |
| 51 | depth -= 1 |
| 52 | i += 1 |
| 53 | body = text[brace_start + 1 : i - 1] |
| 54 | |
| 55 | properties = _parse_properties(body) |
| 56 | interfaces[name] = {"extends": sorted(extends), "properties": properties} |
| 57 | pos = i |
| 58 | return interfaces |
| 59 | |
| 60 | |
| 61 | def _parse_properties(body: str) -> dict: |
no test coverage detected