Skip to content

fix(js): build else branches into the CFG (#206) - #207

Merged
DaisukeYoda merged 1 commit into
mainfrom
fix/206-else-clause
Oct 15, 2026
Merged

DaisukeYoda merged 1 commit into
mainfrom
fix/206-else-clause

Conversation

@DaisukeYoda

Copy link
Copy Markdown
Member

Fixes #206.

The parser kept the alternative of an if statement as a generic else_clause node. The CFG builder did not look inside it, so the statements in an else were never built into the CFG. An else if added no decision point, and a return in an else did not end its branch.

buildIfStatement now stores the statement inside the else_clause as Alternate: a block, or the next if of an else if chain. Nesting depth no longer needs to unwrap the clause, so isElseIf is removed.

Effects:

  • Every else if adds one to cyclomatic complexity. On imbue-ai/latchkey total complexity rises from 2448 to 2463, and on sindresorhus/got from 9924 to 9988. Health scores do not change on either repo.
  • Code after an if/else whose branches all return is reported as unreachable_branch.
  • The else subtree loses one wrapper node, so clone similarity changes slightly (got: 2146 to 2139 clone pairs).

@DaisukeYoda
DaisukeYoda merged commit a3b9681 into main Oct 15, 2026
4 checks passed
@DaisukeYoda
DaisukeYoda deleted the fix/206-else-clause branch October 15, 2026 02:17
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.

js: else clauses are not built into the CFG, so else-if conditions are not counted and returns in else are missed

1 participant