Skip to content

Preserve the ELSE branch when serializing IF statements - #2971

Merged
mathiasrw merged 1 commit into
AlaSQL:developfrom
ZainnQureshii:fix/if-else-serialization
Nov 9, 2026
Merged

mathiasrw merged 1 commit into
AlaSQL:developfrom
ZainnQureshii:fix/if-else-serialization

Conversation

@ZainnQureshii

Copy link
Copy Markdown
Contributor

Serializing an IF statement repeats the THEN statement after ELSE, so

alasql.parse('IF FALSE SELECT VALUE 1 ELSE SELECT VALUE 2').toString()
// 'IF FALSE SELECT VALUE 1 ELSE SELECT VALUE 1'

and running the serialized SQL gives a different result from the original. yy.If.prototype.toString in src/68if.js used this.thenstat for the ELSE branch; it now uses this.elsestat.

A new case in test/test206.js checks the full serialized string. It fails without the fix and passes with it. With sh build.sh and yarn test-only, the whole suite passes (2556 pass, 0 fail), and Prettier is clean on both files.

CASE serialization has a related problem, but #2675 and #2750 hold expression-text changes for 5.0, so it is left out here.

Prepared with AI assistance (Claude Code) and reviewed with GitHub Copilot.

🤖 Generated with Claude Code

yy.If.prototype.toString wrote thenstat after ELSE, so
IF FALSE SELECT VALUE 1 ELSE SELECT VALUE 2 serialized as
IF FALSE SELECT VALUE 1 ELSE SELECT VALUE 1. Use elsestat instead
and add a regression test that checks the full serialized SQL.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mathiasrw

Copy link
Copy Markdown
Member

Love it. Thank you!

@mathiasrw
mathiasrw merged commit 838c927 into AlaSQL:develop Nov 9, 2026
10 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.

2 participants