Commit ce1a193
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
1 file changed
+2
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
290 | 290 | | |
291 | 291 | | |
292 | 292 | | |
293 | | - | |
294 | | - | |
| 293 | + | |
| 294 | + | |
295 | 295 | | |
296 | 296 | | |
297 | 297 | | |
| |||
0 commit comments