First-pass classification of a single physical line.
(raw: str)
| 293 | |
| 294 | |
| 295 | def physical_kind(raw: str) -> str: |
| 296 | """First-pass classification of a single physical line.""" |
| 297 | stripped = raw.rstrip() |
| 298 | text = stripped.strip() |
| 299 | |
| 300 | if not text: |
| 301 | return "blank" |
| 302 | if text.startswith("//") or text.startswith("/*") or text.startswith("*"): |
| 303 | return "comment" |
| 304 | if _ID_LINE.match(stripped): |
| 305 | return "id" |
| 306 | |
| 307 | # Classify by net brace delta on the sanitized text so lines with |
| 308 | # balanced inline braces (`const x = {}`) aren't mistaken for closers. |
| 309 | delta = _brace_delta_raw(stripped) |
| 310 | if delta > 0: |
| 311 | return "open" |
| 312 | if delta < 0: |
| 313 | return "close" |
| 314 | |
| 315 | # Net-zero lines — treat `}` or `} else {` style only if the only brace |
| 316 | # action on the line is a single close at the start. |
| 317 | if text == "}" and not _SIMPLE_PROP.match(stripped): |
| 318 | return "close" |
| 319 | |
| 320 | if _HANDLER.match(stripped): |
| 321 | return "handler" |
| 322 | if _SIMPLE_PROP.match(stripped): |
| 323 | return "prop" |
| 324 | return "other" |
| 325 | |
| 326 | |
| 327 | def opens_js_body(raw: str) -> bool: |
no test coverage detected