Skip to content

fix: top-level switch statements silently dropped#399

Merged
cs01 merged 2 commits intomainfrom
fix/toplevel-switch-statement
Mar 14, 2026
Merged

fix: top-level switch statements silently dropped#399
cs01 merged 2 commits intomainfrom
fix/toplevel-switch-statement

Conversation

@cs01
Copy link
Owner

@cs01 cs01 commented Mar 14, 2026

Summary

  • switch statements at the top level (outside functions) were silently dropped by both parsers — no error, just ignored
  • Both parser-ts and parser-native now handle top-level switch by transforming to if-else chains (same as inside functions)
  • Also discovered that braces in switch cases cause the switch-to-if-else transform to treat them as fall-through (Block nodes return null from transformStatement) — used brace-free case syntax to match existing patterns

Test plan

  • New test fixture control-flow/switch-string-toplevel.ts
  • All existing tests pass
  • Self-hosting (Stage 0 + Stage 1) passes
  • Native compiler correctly compiles top-level switch

🤖 Generated with Claude Code

@cs01 cs01 merged commit 4c9018d into main Mar 14, 2026
17 of 18 checks passed
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