Skip to content

Commit 14a2003

Browse files
author
Giancarlo Erra
committed
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.
1 parent 55d1f81 commit 14a2003

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

src/services/graph-symbols.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,11 @@ function extractFromDart(
399399
};
400400

401401
// ── Top-level declarations (ordered walk so signature/body pairs line up) ──
402+
// Dart 3.3 `extension type` is NOT handled: the vendored grammar
403+
// (@ast-grep/lang-dart 0.0.7) predates the syntax and parses it to ERROR
404+
// nodes (no extension_type_declaration kind exists), so such declarations
405+
// degrade to "not extracted" while the rest of the file extracts normally.
406+
// Revisit when the upstream grammar adds the kind.
402407
const topLevel = kidsOf(root);
403408
for (let i = 0; i < topLevel.length; i++) {
404409
const node = topLevel[i];

tests/unit/graph-symbols.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,26 @@ void main() {
575575
expect(callees).toContain("helper");
576576
});
577577

578+
it("degrades gracefully on Dart 3.3 extension types (unsupported by grammar 0.0.7)", () => {
579+
// The vendored tree-sitter grammar predates `extension type` and parses
580+
// it to ERROR nodes. The contract: no throw, no bogus symbols from the
581+
// ERROR region, and the rest of the file still extracts normally.
582+
const src = `
583+
extension type Meters(int value) {
584+
int get inKm => value ~/ 1000;
585+
}
586+
587+
class Real {
588+
void work() {}
589+
}
590+
`;
591+
const out = extractSymbolsAndCalls(src, "dart" as unknown as Lang, ".dart", "lib/m.dart");
592+
expect(out.symbols.some((s) => s.qualifiedName === "Real" && s.kind === "class")).toBe(true);
593+
expect(out.symbols.some((s) => s.qualifiedName === "Real.work" && s.kind === "method")).toBe(true);
594+
// The unsupported declaration produces no symbol named Meters
595+
expect(out.symbols.some((s) => s.name === "Meters")).toBe(false);
596+
});
597+
578598
it("detects main() so Dart apps get a conventional entry point", () => {
579599
const src = `
580600
void main() {

0 commit comments

Comments
 (0)