Skip to content

feat(parsers): add Dart / Flutter language support#19

Merged
tob-scott-a merged 1 commit intomainfrom
dart-parser
Apr 23, 2026
Merged

feat(parsers): add Dart / Flutter language support#19
tob-scott-a merged 1 commit intomainfrom
dart-parser

Conversation

@tob-scott-a
Copy link
Copy Markdown
Collaborator

Uses tree-sitter-language-pack's dart grammar (transitive dep, no new installs). Extracts:

  • Top-level functions (paired from function_signature + function_body sibling nodes; Dart's grammar keeps them as separate AST siblings rather than nesting them, which required a custom signature-pairing walker).
  • Classes, including abstract classes.
  • Methods inside class bodies (method_signature + function_body pairs).
  • Abstract methods (declaration -> function_signature, no body).
  • Parameters and return types.
  • Imports — package: and dart: URIs captured as dependencies.

Calls in Dart aren't a single AST node — they're an identifier followed by a selector carrying an argument_part. Added _collect_dart_calls to walk bodies, detect argument-bearing selectors, and reconstruct the callee name from the preceding identifier/selector chain (handles both plain calls b() and method calls obj.method()).

Entrypoint detector:

  • @pragma('vm:entry-point') — Dart's explicit native-callable marker. Used for FFI callbacks, platform-channel handlers, and deferred loading targets; these are attacker-reachable from the host platform.

Flutter lifecycle methods (build, initState, dispose) are NOT flagged by default because they run in-process and aren't directly attacker-reachable. Users who want them tagged can add them via the override file.

Known gaps (documented in the parser docstring): throw statements aren't yet added to exception_types — parallel to Swift/Kotlin, the throw AST node overlaps with other control-transfer forms.

12 new tests: Dart parser, Dart entrypoint detection. README supported-languages and framework-coverage tables updated.

Roadmap left before v0.2.0: Option A (Go/Ruby/C++ entrypoint detectors) and Option B (branches + docstring in JSON export).

Uses tree-sitter-language-pack's dart grammar (transitive dep, no new
installs). Extracts:

- Top-level functions (paired from function_signature + function_body
  sibling nodes; Dart's grammar keeps them as separate AST siblings
  rather than nesting them, which required a custom signature-pairing
  walker).
- Classes, including abstract classes.
- Methods inside class bodies (method_signature + function_body pairs).
- Abstract methods (declaration -> function_signature, no body).
- Parameters and return types.
- Imports — `package:` and `dart:` URIs captured as dependencies.

Calls in Dart aren't a single AST node — they're an identifier followed
by a selector carrying an argument_part. Added _collect_dart_calls to
walk bodies, detect argument-bearing selectors, and reconstruct the
callee name from the preceding identifier/selector chain (handles both
plain calls `b()` and method calls `obj.method()`).

Entrypoint detector:

- `@pragma('vm:entry-point')` — Dart's explicit native-callable marker.
  Used for FFI callbacks, platform-channel handlers, and deferred
  loading targets; these are attacker-reachable from the host platform.

Flutter lifecycle methods (`build`, `initState`, `dispose`) are NOT
flagged by default because they run in-process and aren't directly
attacker-reachable. Users who want them tagged can add them via the
override file.

Known gaps (documented in the parser docstring): `throw` statements
aren't yet added to exception_types — parallel to Swift/Kotlin, the
throw AST node overlaps with other control-transfer forms.

12 new tests: Dart parser, Dart entrypoint detection. README
supported-languages and framework-coverage tables updated.

Roadmap left before v0.2.0: Option A (Go/Ruby/C++ entrypoint
detectors) and Option B (branches + docstring in JSON export).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@tob-scott-a tob-scott-a merged commit 8e20700 into main Apr 23, 2026
13 checks passed
@tob-scott-a tob-scott-a deleted the dart-parser branch April 23, 2026 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant