True when `raw` ends with `{` and that `{` opens a JavaScript body. Heuristic: the line matches a QML handler pattern (`onSomething: {`), a Component.onXxx attachment, or a JavaScript `function ... {` or arrow-function `... => {` body. Anything of the form `Foo {` or `Foo.Bar {` at
(raw: str)
| 325 | |
| 326 | |
| 327 | def opens_js_body(raw: str) -> bool: |
| 328 | """True when `raw` ends with `{` and that `{` opens a JavaScript body. |
| 329 | |
| 330 | Heuristic: the line matches a QML handler pattern (`onSomething: {`), |
| 331 | a Component.onXxx attachment, or a JavaScript `function ... {` or |
| 332 | arrow-function `... => {` body. Anything of the form `Foo {` or |
| 333 | `Foo.Bar {` at the start of a line is a QML object declaration and is |
| 334 | NOT a JS body. |
| 335 | """ |
| 336 | stripped = raw.rstrip() |
| 337 | if not stripped.endswith("{"): |
| 338 | return False |
| 339 | |
| 340 | text = stripped.strip() |
| 341 | sanitized = _strip_strings_and_comments(text) |
| 342 | |
| 343 | # JavaScript: `function name(args) {` or `function (args) {` |
| 344 | if re.match(r"^\s*function\b", sanitized): |
| 345 | return True |
| 346 | |
| 347 | # Arrow function body: `... => {` |
| 348 | if "=>" in sanitized: |
| 349 | return True |
| 350 | |
| 351 | # Handler or attachment with a body: `onClicked: {`, `Component.onCompleted: {`, |
| 352 | # `Keys.onPressed: {`, etc. Anything that has `: {` at the end. |
| 353 | if re.search(r":\s*\{\s*$", sanitized): |
| 354 | return True |
| 355 | |
| 356 | return False |
| 357 | |
| 358 | |
| 359 | def is_continuation(prev_kind: str, raw: str) -> bool: |
no test coverage detected