| 49 | } |
| 50 | |
| 51 | export class ExecutionState implements BlockStateController { |
| 52 | private readonly blockStates: Map<string, BlockState> |
| 53 | private readonly executedBlocks: Set<string> |
| 54 | |
| 55 | constructor(blockStates?: Map<string, BlockState>, executedBlocks?: Set<string>) { |
| 56 | this.blockStates = blockStates ?? new Map() |
| 57 | this.executedBlocks = executedBlocks ?? new Set() |
| 58 | } |
| 59 | |
| 60 | getBlockStates(): ReadonlyMap<string, BlockState> { |
| 61 | return this.blockStates |
| 62 | } |
| 63 | |
| 64 | getExecutedBlocks(): ReadonlySet<string> { |
| 65 | return this.executedBlocks |
| 66 | } |
| 67 | |
| 68 | getBlockOutput(blockId: string, currentNodeId?: string): NormalizedBlockOutput | undefined { |
| 69 | const normalizedId = normalizeLookupId(blockId) |
| 70 | if (normalizedId !== blockId) { |
| 71 | return this.blockStates.get(blockId)?.output |
| 72 | } |
| 73 | |
| 74 | if (currentNodeId) { |
| 75 | const scopedOutput = this.getScopedBlockOutput(blockId, currentNodeId) |
| 76 | if (scopedOutput !== undefined) { |
| 77 | return scopedOutput |
| 78 | } |
| 79 | |
| 80 | if (extractOuterBranchIndex(currentNodeId) !== undefined) { |
| 81 | return undefined |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | const direct = this.blockStates.get(blockId)?.output |
| 86 | if (direct !== undefined) { |
| 87 | return direct |
| 88 | } |
| 89 | |
| 90 | if (currentNodeId && extractBranchSuffix(currentNodeId) === '') { |
| 91 | const stableBranchZeroOutput = this.blockStates.get( |
| 92 | buildOuterBranchScopedId(blockId, 0) |
| 93 | )?.output |
| 94 | if (stableBranchZeroOutput !== undefined) { |
| 95 | return stableBranchZeroOutput |
| 96 | } |
| 97 | |
| 98 | const branchZeroOutput = this.blockStates.get( |
| 99 | `${blockId}₍0₎${extractLoopSuffix(currentNodeId)}` |
| 100 | )?.output |
| 101 | if (branchZeroOutput !== undefined) { |
| 102 | return branchZeroOutput |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | for (const [storedId, state] of this.blockStates.entries()) { |
| 107 | if (normalizeLookupId(storedId) === blockId) { |
| 108 | return state.output |
nothing calls this directly
no outgoing calls
no test coverage detected