From 50001fd0d3f6454475a0b0d293fbbcb367508adf Mon Sep 17 00:00:00 2001 From: Ray Morris Date: Wed, 31 Dec 2025 17:40:51 -0600 Subject: [PATCH] Fix transpiler conflict detection and AST consistency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This addresses two issues identified by Qodo bot code review: Issue #3: Conflict detection indexing bug - Previously only ifthen handlers got unique keys - All on.always() blocks collapsed to single key, causing: * False positives: assignments in different blocks flagged as conflicts * Disabled race detection: check requires multiple handlers but all collapsed to 1 - Fix: Give every handler a unique index regardless of type - Location: js/transpiler/transpiler/analyzer.js:528-530 Issue #5: Raw values not wrapped in Literal nodes - >= and <= optimization passed raw numbers instead of AST nodes - Fix: Wrap constValue±1 in {type: 'Literal', value: ...} objects - Maintains AST consistency throughout pipeline - Location: js/transpiler/transpiler/condition_generator.js:300,307 All 27 transpiler test suites pass with 0 failures. --- js/transpiler/transpiler/analyzer.js | 9 +++------ js/transpiler/transpiler/condition_generator.js | 4 ++-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/js/transpiler/transpiler/analyzer.js b/js/transpiler/transpiler/analyzer.js index 4319e6336..920e175a1 100644 --- a/js/transpiler/transpiler/analyzer.js +++ b/js/transpiler/transpiler/analyzer.js @@ -525,12 +525,9 @@ class SemanticAnalyzer { let stmtIndex = 0; for (const stmt of ast.statements) { if (stmt && stmt.type === 'EventHandler') { - // Each if statement gets a unique key - we want to detect multiple - // assignments within the SAME if block, not across different if - // statements that happen to have the same condition - const handlerKey = stmt.handler === 'ifthen' ? - `ifthen:${stmtIndex}` : - stmt.handler; + // Each handler gets a unique key - we want to detect multiple + // assignments within the SAME handler, not across different handlers + const handlerKey = `${stmt.handler}:${stmtIndex}`; if (!handlerAssignments.has(handlerKey)) { handlerAssignments.set(handlerKey, new Map()); diff --git a/js/transpiler/transpiler/condition_generator.js b/js/transpiler/transpiler/condition_generator.js index 672b39315..e9d39d05f 100644 --- a/js/transpiler/transpiler/condition_generator.js +++ b/js/transpiler/transpiler/condition_generator.js @@ -297,14 +297,14 @@ class ConditionGenerator { return this.generateBinary({ ...condition, operator: '>', - right: constValue - 1 + right: { type: 'Literal', value: constValue - 1 } }, activatorId); } else { // x <= 5 → x < 6 return this.generateBinary({ ...condition, operator: '<', - right: constValue + 1 + right: { type: 'Literal', value: constValue + 1 } }, activatorId); } }