diff --git a/compiler/src/generators/typescript-state-machine.ts b/compiler/src/generators/typescript-state-machine.ts index 184c3f7..b4cfeaa 100644 --- a/compiler/src/generators/typescript-state-machine.ts +++ b/compiler/src/generators/typescript-state-machine.ts @@ -488,7 +488,8 @@ function rewriteExpr(expr: string, stateVarNames: Set, mapVarNames: Set< ts = ts.replace(/\bnot\s+/g, '!'); // 5d2: and -> &&, or -> || (logical operators) - ts = ts.replace(/\band\b/g, '&&').replace(/\bor\b/g, '||'); + // Avoid matching inside method calls like .or( or .and( + ts = ts.replace(/([^.]\s*)\band\b(?!\s*\()/g, '$1&&').replace(/([^.]\s*)\bor\b(?!\s*\()/g, '$1||'); // 5d3: Strip SpeckDL comments (// ...) before TS processing ts = ts.replace(/\/\/.*$/gm, ''); @@ -509,6 +510,9 @@ function rewriteExpr(expr: string, stateVarNames: Set, mapVarNames: Set< return `new Map([[${k}, ${v}]])`; }); + // 5d6: emptySet -> new Set() + ts = ts.replace(/\bemptySet\b/g, 'new Set()'); + // 5e: Clean up trailing empty comparisons (===) — expression has no RHS after old() removal // "accounts[t.from].debits_posted ===" -> "accounts[t.from].debits_posted === accounts[t.from].debits_posted" ts = ts.replace(/(\S+)\s*===\s*$/g, '$1 === $1');