feat: v2 array index round-trip with operator_add and local variable array support#312
Merged
Merged
Conversation
…t local variable arrays In v2 array syntax, adjustIndex now always wraps the index in operator_add(index, 1) with @ruby:array:index comment instead of directly incrementing literals. This enables correct round-trip conversion for both literal indices (@A[0]) and variable indices (@A[@b]). Also adds support for local variable array assignment (a = ["a", "b"]) and indexing (a[0]) in v2 mode. v1 list() syntax remains unchanged — indices are stored as-is with no operator_add wrapper. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
🚀 Preview deployed: https://smalruby.jp/smalruby3-editor/feature/array-index-roundtrip/ |
github-actions Bot
pushed a commit
that referenced
this pull request
Mar 15, 2026
…-index-roundtrip feat: v2 array index round-trip with operator_add and local variable array support
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
adjustIndexが常にoperator_add(index, 1)でラップするように変更。リテラルインデックス (@a[0]) と変数インデックス (@a[@b]) の両方で正しいラウンドトリップ変換が可能にa = ["a", "b"]) とインデックスアクセス (a[0]) を v2 モードでサポートlist()構文は変更なし — インデックスはそのまま格納(operator_addラッパーなし)Changes Made
Converter (
variables.js)adjustIndex: リテラルの直接インクリメントからoperator_add(index, 1)+@ruby:array:indexコメントに変更convertToListBlock: ローカル変数 (scope === 'local') のサポートを追加registerOnVasgn: ローカル変数の配列リテラル代入を追加(@ruby:lvar:コメント付き)Generator (
data.js)getListName:@ruby:lvar:コメントからローカル変数名を取得するロジックを追加getListIndex: コメント検出を@ruby:array:index_offsetから@ruby:array:indexに変更data_deletealloflist:startsWithから正規表現に変更(複合コメント対応)Tests
variables-list-v1.test.js: v1 list converter テスト 15件(新規)variables-v2-array.test.js: v2 array roundtrip テスト 14件(新規)variables-array-local.test.js: ローカル変数配列テスト 6件(新規)operator_addラッパーに更新Test Coverage
Related Issues
Fixes array indexing round-trip issues found during #311 verification.