Skip to content

Conversation

Copy link

Copilot AI commented Nov 21, 2025

Completes the migration from custom when(() => ...) syntax to standard JavaScript if() statements. The parser already supports if statements and converts them to INAV logic conditions. This PR updates all examples, documentation, and diagnostics to use and promote the modern syntax.

Changes Made

  • Examples (tabs/transpiler/examples/index.js) - Converted all 7 examples from when(() => condition, () => { ... }) to if (condition) { ... } syntax
  • Type definitions (tabs/transpiler/api/types.js) - Marked when() function as @deprecated to discourage its use
  • Diagnostics (tabs/transpiler/editor/diagnostics.js) - Updated to warn users when using deprecated when() syntax and suggest if statements instead
  • Parser comments (tabs/transpiler/transpiler/parser.js) - Updated all comments to reference if statements and logic conditions instead of when()

Example Conversion

// Old syntax (deprecated)
when(() => flight.homeDistance > 100, () => {
  override.vtx.power = 3;
});

// New syntax (current)
if (flight.homeDistance > 100) {
  override.vtx.power = 3;
}

The migration ensures users see modern JavaScript syntax in all examples and receive editor warnings if they attempt to use the deprecated when() syntax.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI mentioned this pull request Nov 21, 2025
Copilot AI changed the title [WIP] Fix custom syntax in programming transpiler to standard JavaScript Guidance on completing when() to if() syntax migration Nov 21, 2025
Copilot AI requested a review from sensei-hacker November 21, 2025 23:28
Copy link
Owner

@sensei-hacker sensei-hacker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made some changes

@sensei-hacker
Copy link
Owner

@copilot I have made some changes. Does you see anything else that needs to be done?

Co-authored-by: sensei-hacker <1971284+sensei-hacker@users.noreply.github.com>
Copy link
Author

Copilot AI commented Nov 22, 2025

@copilot I have made some changes. Does you see anything else that needs to be done?

I've completed the migration from when(() => ...) to standard JavaScript if statements. Changes made in commit 620c192:

1. Updated all examples - All 7 code examples now use if (condition) { } instead of when(() => condition, () => { })

2. Deprecated when() function - Added @deprecated tag to when() in type definitions (tabs/transpiler/api/types.js)

3. Updated diagnostics - Now warns users when they use when() and suggests using if statements instead (tabs/transpiler/editor/diagnostics.js)

4. Updated parser comments - Replaced all references to "when()" with "if statements" or "logic conditions" (tabs/transpiler/transpiler/parser.js)

The migration is now complete. All examples demonstrate the modern syntax, and users will be guided away from the deprecated when() syntax through editor warnings.

Copilot AI changed the title Guidance on completing when() to if() syntax migration Complete when() to if() syntax migration in transpiler Nov 22, 2025
Copilot AI requested a review from sensei-hacker November 22, 2025 03:05
sensei-hacker added a commit that referenced this pull request Dec 14, 2025
When a sticky has an activator, it's defined inside an if-block but may
be referenced from outside (e.g., by a root-level delay). The old code
relied on JavaScript var hoisting, which worked but was confusing.

Fix: Pre-declare sticky variables at top level when they have activators.
- Before: if (cond) { var latch1 = sticky({...}); }
- After:  var latch1; ... if (cond) { latch1 = sticky({...}); }

Changes:
- decompiler.js: Add predeclaredStickyVars set, pre-declare before roots
- renderStickyWithLatch: Use assignment-only for pre-declared vars
- simple_test_runner.cjs: Add toBeTruthy/toBeFalsy assertions
- sticky_scope_test.cjs: New test for scope fix verification
- decompiler.test.cjs: Update test expectations
sensei-hacker added a commit that referenced this pull request Dec 31, 2025
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants