diff --git a/graphify/extract.py b/graphify/extract.py index 8bb0bfcee..24aa1a11e 100644 --- a/graphify/extract.py +++ b/graphify/extract.py @@ -2387,10 +2387,13 @@ def _svelte_mask_non_script(src: str) -> tuple[str, str | None]: continue start, end = m.start(2), m.end(2) chars[start:end] = src[start:end] - # Terminate the region in place of the following `<`, so two scripts on - # one line don't run together into a single statement. - if end < len(chars) and chars[end] == " ": - chars[end] = ";" + # Terminate the region in place of the closing ` dict: """ try: src = path.read_text(encoding="utf-8", errors="replace") - except OSError: - return {"nodes": [], "edges": []} + except OSError as e: + return {"nodes": [], "edges": [], "error": str(e)} masked, lang = _svelte_mask_non_script(src) config = _JS_CONFIG if lang in ("js", "jsx") else _TS_CONFIG diff --git a/tests/test_svelte_extraction.py b/tests/test_svelte_extraction.py index bd6595edf..68d8b4b34 100644 --- a/tests/test_svelte_extraction.py +++ b/tests/test_svelte_extraction.py @@ -164,6 +164,38 @@ def test_extract_svelte_scripts_on_one_line_do_not_merge(tmp_path): assert "b()" in _labels(result) +def test_extract_svelte_line_comment_does_not_swallow_next_script(tmp_path): + """A `//` comment ending one block must not hide a block on the same line.""" + component = _write( + tmp_path / "src/Commented.svelte", + "\n" + "\n", + ) + result = extract_svelte(component) + assert result.get("parse_errors") is None + labels = _labels(result) + assert labels.get("b()") == "L1" + assert labels.get("c()") == "L2" + + +def test_extract_svelte_comment_after_unterminated_statement(tmp_path): + """A statement with no `;` before the `//` comment still ends at the block.""" + component = _write( + tmp_path / "src/Unterminated.svelte", + "\n", + ) + result = extract_svelte(component) + assert result.get("parse_errors") is None + assert _labels(result).get("b()") == "L1" + + +def test_extract_svelte_unreadable_file_reports_error(tmp_path): + """A file that cannot be read is reported, not returned as an empty result.""" + result = extract_svelte(tmp_path / "missing" / "Gone.svelte") + assert result["nodes"] == [] and result["edges"] == [] + assert "error" in result + + def test_extract_svelte_markup_only_component_does_not_crash(tmp_path): """A `.svelte` file need not have a `