Skip to content

feat: support Ruby hash literals and bracket access with dual-list storage#318

Merged
takaokouji merged 6 commits intodevelopfrom
feature/ruby-hash-support
Mar 16, 2026
Merged

feat: support Ruby hash literals and bracket access with dual-list storage#318
takaokouji merged 6 commits intodevelopfrom
feature/ruby-hash-support

Conversation

@takaokouji
Copy link

@takaokouji takaokouji commented Mar 16, 2026

Summary

v2 限定で、Ruby ハッシュリテラルとブラケットアクセスを、既存の Scratch リスト2本(_hash_<name>_keys_ / _hash_<name>_values_)にマッピングして実現する。

Closes #315

Implementation Steps

  • Phase 1: ハッシュリテラル$a = {name: "Alice", age: 30} の converter + generator(TDD)
  • Phase 2: ハッシュ読み取り$a[:name] / $a["name"] の converter + generator(TDD)
  • Phase 3: ハッシュ書き込み(upsert)$a[:name] = "Bob" の delete+push パターン converter + generator(TDD)
  • Phase 4: v1 バージョンゲーティング — v1 でハッシュ構文使用時のエラーメッセージ
  • Phase 5: ラウンドトリップテスト — リテラル/読取/書込/sym・str 混在/ローカル変数のラウンドトリップ
  • Phase 6: ブラウザ確認 — production build での Playwright MCP 確認

Definition of Done

  • ユニットテスト pass (12 tests)
  • ラウンドトリップテスト pass (16 tests)
  • lint pass
  • CI green
  • ブラウザ確認(Playwright MCP - production build):
    • $a = {name: "Alice", age: 30} → ブロック化 → Ruby 復元
    • $a[:name] 読み取りラウンドトリップ
    • $a[:name] = "Bob" 書き込み(既存キー更新)ラウンドトリップ
    • $a[:new_key] = "value" 書き込み(新規キー追加)ラウンドトリップ
    • $a = {"foo" => "bar"} 文字列キーのラウンドトリップ
    • $a = {} 空ハッシュのラウンドトリップ
    • $a = {x: 10, y: 20} 整数値ハッシュのラウンドトリップ
    • v1 モードでハッシュ構文(リテラル/読み取り/書き込み)を書くとエラー表示

Production Build Fix

visitHashNode / visitKeywordHashNodeelement.constructor.name === 'AssocNode' を使用していたが、production build (esbuild minify) でクラス名がマングルされるため element.toJSON().type === 'AssocNode' に修正。

Test Coverage

  • 12 unit tests for hash converter (literal, read, write, v1 gating, instance var)
  • 16 roundtrip tests for hash generator (all scopes, key types, operations, local vars)
  • 245 total tests pass across 45 test suites with zero regressions

takaokouji and others added 3 commits March 16, 2026 09:41
Implement Ruby hash literal syntax ($a = {name: "Alice", age: 30})
using dual-list storage (_hash_<name>_keys_ + _hash_<name>_values_).
Supports symbol keys, string keys, hash rocket syntax, empty hashes,
and global/instance variable scopes.

Part of #315.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Implement $a[:name] and $a["name"] hash bracket read using
data_itemoflist(data_itemnumoflist(key, keys_list), values_list).
Also pre-implements convertHashSet helper for Phase 3.

Part of #315.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Implement $a[:name] = "Bob" using delete+push pattern (4 blocks).
Leverages Scratch index 0 = LIST_INVALID = no-op for if-less upsert.
Supports both symbol and string keys.

Part of #315.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link

takaokouji and others added 3 commits March 16, 2026 09:46
…e 4)

Hash literal, read, and write operations now throw descriptive errors
when used in Ruby version 1. Added Japanese and hiragana locale strings.

Part of #315.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…hase 5)

Handle @ruby:lvar prefix in hash get/set comments for local variables.
Generator now extracts variable name from lvar comment when present.
Add locale messages and comprehensive roundtrip tests for all scenarios.

Part of #315.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
constructor.name is mangled by terser in production builds, causing
visitHashNode and visitKeywordHashNode to produce empty hash Maps.
This fixes hash literal entries being lost in production.

Part of #315.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@takaokouji takaokouji merged commit e83363f into develop Mar 16, 2026
9 checks passed
@takaokouji takaokouji deleted the feature/ruby-hash-support branch March 16, 2026 02:31
github-actions bot pushed a commit that referenced this pull request Mar 16, 2026
…hash-support

feat: support Ruby hash literals and bracket access with dual-list storage
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.

feat: support Ruby hash literals and bracket access with dual-list storage

1 participant