- x in someSet → someSet.has(x) - x in someMap.keys → someMap.has(x) - x notIn someMap.keys → !someMap.has(x) - m[k] → m.get(k) for Map state variables - s.size() → s.size (property, not method) - Track Map-typed state variables via mapVarNames for accurate .get() translation - Thread mapVarNames through emitAction and rewriteExpr All 41 tests passing. TigerBeetleLedger now generates correct TypeScript with .get() for Map access and .has() for Set membership. Part of M0.1: Fix TS generator bugs (speckl#18)
34 lines
651 B
TypeScript
34 lines
651 B
TypeScript
// Auto-generated by speckl-compile from ToggleSwitch
|
|
// DO NOT EDIT MANUALLY — regenerate from .speckdl source
|
|
|
|
export const ToggleSwitchState = {
|
|
Open: 'open',
|
|
Closed: 'closed',
|
|
} as const;
|
|
export type ToggleSwitchState = typeof ToggleSwitchState[keyof typeof ToggleSwitchState];
|
|
|
|
|
|
|
|
|
|
export class ToggleSwitchMachine {
|
|
isOn: boolean;
|
|
decisionLog: any[] = [];
|
|
|
|
constructor() {
|
|
// No init block defined
|
|
}
|
|
|
|
TurnOn() {
|
|
if (!(not this.isOn)) throw new Error('Guard failed: not this.isOn');
|
|
this.isOn = true;
|
|
}
|
|
|
|
TurnOff() {
|
|
if (!(this.isOn)) throw new Error('Guard failed: this.isOn');
|
|
this.isOn = false;
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|