Skip to content

Bash extractor: a call after elif, then or do is lost when the line before holds only assignments (v=a w="$(f)") #5572

Backlog

Description

@yashsaxena

What happens

In a function, a branch whose last line holds only assignments, followed by elif, loses the call elif makes:

  if [ -z "${1:-}" ]; then
    v=a w="$(echo b)"
  elif ok "$1"; then

tree-sitter-bash reads v=a w="$(echo b)" and the next line's elif ok "$1" as one command, whose name is the keyword elif.
The call walk takes elif as the callee, so ok gets no calls edge.
The same happens after then, else, do, while and until.

Reproduced on graphifyy 0.9.122 (newest on PyPI), installed with pip, nothing patched, Python 3.12, Ubuntu.

Reproduction

Two files in a new git repo:

# bin/tool
#!/usr/bin/env bash
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
. "$ROOT/lib/check.sh"
main() {
  if [ -z "${1:-}" ]; then
    v=a w="$(echo b)"
  elif ok "$1"; then
    echo "$v$w"
  fi
}
main "$@"
# lib/check.sh
ok() { [ -n "$1" ]; }

Command:

graphify extract "$PWD" --code-only --out /tmp/out
jq -r '.links[] | select(.relation != "contains" and .relation != "defines")
       | "\(.relation) \(.source) -> \(.target)"' /tmp/out/graphify-out/graph.json

Expected

imports_from bin/tool -> lib/check.sh
calls bin/tool main -> lib/check.sh ok

Got

calls bin/tool (script) -> bin/tool main
imports_from bin/tool -> lib/check.sh

Cause and fix

walk_calls takes the command's first child as its name; here that is the keyword.
When the name is one of if then elif else do while until, the call is the first word after it (a ! aside).
We carry this fix as a local patch and will open a PR.

Activity

  1. github-actions commented on Nov 28, 2026

    @github-actions

    Thanks for opening this issue, @yashsaxena. A maintainer will take a look soon.

    If you would like to discuss it in real time, come say hi on our Discord server. For longer-form questions and ideas there is also GitHub Discussions.

    To help us triage, please make sure the report includes what you expected, what actually happened, and the steps (and a small sample) to reproduce it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions