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.
This commit is contained in:
Giancarlo Erra
2026-06-11 12:22:15 +01:00
parent 7bd9eb5308
commit c5a706cc71
2 changed files with 25 additions and 0 deletions
+5
View File
@@ -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];
+20
View File
@@ -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() {