Skip to content

Commit ce1a193

Browse files
committed
Fix JS Programming decompiler replacing spaces with variable names
**Problem:** When decompiling logic conditions with activator hoisting and a stored variable map, all spaces between words were being replaced with custom variable names (e.g., "const min" became "constmin", comments like "INAV JavaScript Programming" became "INAVminJavaScriptminProgramming"). **Root Cause:** In decompiler.js applyCustomVariableNames() at line 293, the code was storing entire objects from hoistedActivatorVars instead of extracting the varName string: const entry = { varName: 'cond1', scopeLcIndex: -1 } When this object was used in a template literal to build a regex pattern: `\\b${entry}\\b` → `\\b[object Object]\\b` In regex, `[object Object]` is a CHARACTER CLASS that matches any single character from the set: {o,b,j,e,c,t,space,O}. This caused the regex pattern `\\b[object Object]\\b` to match spaces between word boundaries, replacing them with the custom variable name. **Fix:** Changed line 293-294 to extract the .varName property: - Before: lcIndexToGeneratedName.set(lcIndex, generatedName); - After: lcIndexToGeneratedName.set(lcIndex, entry.varName); This ensures the regex replacement uses the actual variable name string instead of "[object Object]" character class. **Files Changed:** - js/transpiler/transpiler/decompiler.js **Testing:** Verified with test cases showing the fix prevents space replacement in both code and comments.
1 parent a078606 commit ce1a193

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

js/transpiler/transpiler/decompiler.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,8 @@ class Decompiler {
290290

291291
// Build mapping: LC index -> generated name (cond1, cond2, etc.)
292292
const lcIndexToGeneratedName = new Map();
293-
for (const [lcIndex, generatedName] of this.hoistingManager.hoistedActivatorVars.entries()) {
294-
lcIndexToGeneratedName.set(lcIndex, generatedName);
293+
for (const [lcIndex, entry] of this.hoistingManager.hoistedActivatorVars.entries()) {
294+
lcIndexToGeneratedName.set(lcIndex, entry.varName);
295295
}
296296

297297
// For each LC that has both a custom name and a generated name, rename

0 commit comments

Comments
 (0)