Skip to content

feat: v2 array index round-trip with operator_add and local variable array support#312

Merged
takaokouji merged 1 commit into
developfrom
feature/array-index-roundtrip
Mar 15, 2026
Merged

feat: v2 array index round-trip with operator_add and local variable array support#312
takaokouji merged 1 commit into
developfrom
feature/array-index-roundtrip

Conversation

@takaokouji
Copy link
Copy Markdown

Summary

  • v2 配列構文で adjustIndex が常に operator_add(index, 1) でラップするように変更。リテラルインデックス (@a[0]) と変数インデックス (@a[@b]) の両方で正しいラウンドトリップ変換が可能に
  • ローカル変数への配列代入 (a = ["a", "b"]) とインデックスアクセス (a[0]) を v2 モードでサポート
  • v1 の 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件(新規)
  • 既存テストの INDEX 期待値を operator_add ラッパーに更新

Test Coverage

  • v1 list converter: 15 unit tests (indices stored as-is, no wrapper)
  • v2 array converter: 19 unit tests (operator_add wrapper for indices)
  • v2 array roundtrip: 14 tests (literal/variable indices, all operations)
  • Local variable arrays: 6 unit tests
  • All 1407 tests pass, lint clean

Related Issues

Fixes array indexing round-trip issues found during #311 verification.

…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>
@github-actions
Copy link
Copy Markdown

@takaokouji takaokouji merged commit edf3edf into develop Mar 15, 2026
9 checks passed
@takaokouji takaokouji deleted the feature/array-index-roundtrip branch March 15, 2026 11:46
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
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.

1 participant