-
Notifications
You must be signed in to change notification settings - Fork 0
Complete when() to if() syntax migration in transpiler #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
sensei-hacker
left a comment
There was a problem hiding this 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
|
@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>
I've completed the migration from 1. Updated all examples - All 7 code examples now use 2. Deprecated when() function - Added 3. Updated diagnostics - Now warns users when they use 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 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
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.
Completes the migration from custom
when(() => ...)syntax to standard JavaScriptif()statements. The parser already supportsifstatements and converts them to INAV logic conditions. This PR updates all examples, documentation, and diagnostics to use and promote the modern syntax.Changes Made
tabs/transpiler/examples/index.js) - Converted all 7 examples fromwhen(() => condition, () => { ... })toif (condition) { ... }syntaxtabs/transpiler/api/types.js) - Markedwhen()function as@deprecatedto discourage its usetabs/transpiler/editor/diagnostics.js) - Updated to warn users when using deprecatedwhen()syntax and suggestifstatements insteadtabs/transpiler/transpiler/parser.js) - Updated all comments to referenceifstatements and logic conditions instead ofwhen()Example Conversion
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.