diff --git a/blocks-algo.js b/blocks-algo.js index da752c6..144f59e 100644 --- a/blocks-algo.js +++ b/blocks-algo.js @@ -258,13 +258,14 @@ class WCDecision extends WCBlock { } return; } - visited.add(el); - if (loopTargets && loopTargets.has(el)) { - c += "\n" + el.id + ":"; - } if (el instanceof WCDecision) { + // Decisions manage their own visited tracking inside generateCode. c += el.generateCode(visited, loopTargets); } else { + visited.add(el); + if (loopTargets && loopTargets.has(el)) { + c += "\n" + el.id + ":"; + } c += el.generateOwnCode(); for (const p of el.wcNextFlow) walk(p.toElement); } diff --git a/codegen/index.js b/codegen/index.js index 894af6b..ac05ef5 100644 --- a/codegen/index.js +++ b/codegen/index.js @@ -107,15 +107,14 @@ } return; } - visited.add(el); - - if (loopTargets.has(el)) { - parts.push("\n" + (el.id || "block") + ":"); - } - if (isDecision(el)) { + // Decisions manage their own visited tracking inside generateCode. parts.push(el.generateCode(visited, loopTargets)); } else { + visited.add(el); + if (loopTargets.has(el)) { + parts.push("\n" + (el.id || "block") + ":"); + } parts.push(el.generateOwnCode()); var flow = el.wcNextFlow || el.nextFlow || []; for (var j = 0; j < flow.length; j++) {