MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / opens_js_body

Function opens_js_body

scripts/code-verify.py:327–356  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

325
326
327def 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
359def is_continuation(prev_kind: str, raw: str) -> bool:

Callers 2

find_property_runsFunction · 0.85

Calls 2

searchMethod · 0.45

Tested by

no test coverage detected