From c5a706cc718a3b0743a5451e7c735df9c6cfbfea Mon Sep 17 00:00:00 2001 From: Giancarlo Erra Date: Thu, 11 Jun 2026 12:22:15 +0100 Subject: [PATCH] test(graph): pin graceful degradation for Dart extension types The vendored @ast-grep/lang-dart 0.0.7 grammar predates Dart 3.3 extension types and parses them to ERROR nodes; the kinds a newer tree-sitter-dart exposes (extension_type_declaration) do not exist in this version, so matching on them would be unreachable code. Document the limitation at the walk site and lock in the contract: no throw, no bogus symbols from the ERROR region, and the rest of the file still extracts normally. --- src/services/graph-symbols.ts | 5 +++++ tests/unit/graph-symbols.test.ts | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/services/graph-symbols.ts b/src/services/graph-symbols.ts index 4c7f022..b4b6f5c 100644 --- a/src/services/graph-symbols.ts +++ b/src/services/graph-symbols.ts @@ -399,6 +399,11 @@ function extractFromDart( }; // ── Top-level declarations (ordered walk so signature/body pairs line up) ── + // Dart 3.3 `extension type` is NOT handled: the vendored grammar + // (@ast-grep/lang-dart 0.0.7) predates the syntax and parses it to ERROR + // nodes (no extension_type_declaration kind exists), so such declarations + // degrade to "not extracted" while the rest of the file extracts normally. + // Revisit when the upstream grammar adds the kind. const topLevel = kidsOf(root); for (let i = 0; i < topLevel.length; i++) { const node = topLevel[i]; diff --git a/tests/unit/graph-symbols.test.ts b/tests/unit/graph-symbols.test.ts index aa75c7b..0ab8f83 100644 --- a/tests/unit/graph-symbols.test.ts +++ b/tests/unit/graph-symbols.test.ts @@ -575,6 +575,26 @@ void main() { expect(callees).toContain("helper"); }); + it("degrades gracefully on Dart 3.3 extension types (unsupported by grammar 0.0.7)", () => { + // The vendored tree-sitter grammar predates `extension type` and parses + // it to ERROR nodes. The contract: no throw, no bogus symbols from the + // ERROR region, and the rest of the file still extracts normally. + const src = ` +extension type Meters(int value) { + int get inKm => value ~/ 1000; +} + +class Real { + void work() {} +} +`; + const out = extractSymbolsAndCalls(src, "dart" as unknown as Lang, ".dart", "lib/m.dart"); + expect(out.symbols.some((s) => s.qualifiedName === "Real" && s.kind === "class")).toBe(true); + expect(out.symbols.some((s) => s.qualifiedName === "Real.work" && s.kind === "method")).toBe(true); + // The unsupported declaration produces no symbol named Meters + expect(out.symbols.some((s) => s.name === "Meters")).toBe(false); + }); + it("detects main() so Dart apps get a conventional entry point", () => { const src = ` void main() {