Add JavaScript Programming tab with transpiler#2439
Add JavaScript Programming tab with transpiler#2439sensei-hacker merged 10 commits intoiNavFlight:masterfrom
Conversation
Adds a new JavaScript Programming tab that allows users to write flight logic in JavaScript and transpile it to INAV's logic conditions. - Add Monaco editor integration for code editing - Add transpiler with parser, analyzer, and code generator - Add decompiler to convert existing logic back to JavaScript - Add API definitions for flight, RC, PID, waypoints, etc. - Add new tab UI and navigation integration
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
||||||||||||||||||||||||||||
PR Code Suggestions ✨Latest suggestions up to 097fa09
Previous suggestionsSuggestions up to commit 097fa09
✅ Suggestions up to commit f22e4bd
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
- Expand isActionOperation() to include all action operations - Add decompileActionOrCondition() to properly classify operations - Comparison operations with activators are now skipped (intermediate values) - Convert decompiler tests from Jest to working cjs format - Add test for "comparison with activator" scenario Fixes "Unknown operation 3 (Lower Than) in action" error that occurred when decompiling logic conditions where comparison operations were used as intermediate values with activators.
Changes: - Add collectDescendants() to recursively collect all descendants in activator chains (fixes "Logic condition X has no valid activator" warnings for grandchild conditions) - Expand isActionOperation() with all action operations (fixes "Unknown operation 3 (Lower Than) in action" error) - Build combined AND conditions from chained conditions (chains like LC0→LC1→LC2 now output combined condition) - Output conditions even without actions (can be read externally) - Add chained_conditions.test.cjs with tests for these cases Fixes issues with: - Comparison operations with activators being misidentified as actions - Orphan condition warnings for nested activator chains - Missing output for condition chains without actions
Transpiler fixes: - Fix nested if statements being silently discarded (parser.js, codegen.js) - Fix isAlwaysFalse missing >= and <= operators (optimizer.js) - Synthesize >=, <=, != operators via NOT (condition_generator.js) - a >= b → NOT(a < b) - a <= b → NOT(a > b) - a != b → NOT(a == b) - Support rc[N].value = x syntax for assignments (action_generator.js) - Fix 'use strict' inside comment block (optimizer.js) - Remove debug console.log statements (index.js) UI/Editor fixes: - Fix example dropdown selector (#js-example-select → #examples-select) - Add isDirty check before loading examples (confirm dialog) - Comment out undefined getDefinition() call (diagnostics.js) - Remove ~350 lines of dead Monaco loading code Tests added (107 total): - comparison_operators (6), nested_if (4), optimizer (10) - ui_selectors (2), diagnostics (2), strict_mode (2) - load_example (1), debug_logs (2)
- Fix line:0 adjustment bug in transpiler/index.js (warning.line && check fails for 0) - Fix decompiler stats keys in javascript_programming.js (enabled/total not enabledConditions/totalConditions) - Remove false-positive RC access diagnostic (bare rc[N] is valid, defaults to .value)
RC channels:
- Change from 0-based (rc[0]-rc[17]) to 1-based (rc[1]-rc[18]) to match INAV firmware
- Update action_generator, condition_generator, property_access_checker
- Update API definitions and type declarations
- Add diagnostic warning for rc[0] usage
Decompiler:
- Fix gap handling: use continue instead of break to scan all conditions
- Add blank line output for gaps between logic condition groups
- Preserves user's visual grouping when decompiling
API docs:
- Fix edge() parameter definition to use { duration: X } format
Test fixes:
- Fix auto_import tests to use new ensureInavImport() API (returns object)
- Fix hasInavImport test cases that had false positives
- Add toHaveProperty() assertion to simple_test_runner
- All 154 tests now pass
…and CI build - Parser: Create EventHandler even with empty body if condition exists - Optimizer: Preserve empty-body EventHandlers that have conditions (readable LCs) - ConditionGenerator: Use chained activators for AND conditions (more efficient) - ConditionGenerator: Add CSE cache to avoid duplicate condition generation - Decompiler: Show terminal condition index in readable LC comments - yarn.lock: Fix SSH URL to HTTPS for CI compatibility 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
- Add LC operand decompilation safeguards for chained activators and actions - Fix optimizer numeric truthiness checks (0 is falsy, non-zero is truthy) - Remove unreachable dead code from codegen.js getOperation() - Add Monaco worker URL path validation
…lback - Add cycle detection to decompiler LC operand resolution to prevent infinite recursion on cyclic LC references - Stabilize CSE condition key generation with type-prefixed format to prevent key collisions between different AST node types - Fail explicitly on unsupported comparison operators instead of silently defaulting to EQUAL operation
6feb022 to
097fa09
Compare
Summary
Adds a new JavaScript Programming tab that allows users to write logic condtions (Programming tab) in JavaScript and transpile it to INAV's logic conditions format.
This feature is purely a Configurator enhancement - it does NOT modify the INAV firmware in any way. The transpiler converts JavaScript to the same logic conditions format that INAV already supports.
Features
Supported Operations
Example
Screenshots
Documentation
inav/docs/javascript_programming/There is also a test suite included. That accounts for most of the files. :)