Skip to content

fix: preserve class inheritance (superclass) during Ruby round-trip#290

Merged
takaokouji merged 3 commits intodevelopfrom
fix/preserve-class-inheritance
Mar 13, 2026
Merged

fix: preserve class inheritance (superclass) during Ruby round-trip#290
takaokouji merged 3 commits intodevelopfrom
fix/preserve-class-inheritance

Conversation

@takaokouji
Copy link

Summary

Fixes #289 — Preserve class inheritance (superclass) during Ruby round-trip conversion.

Previously, class Sprite1 < ::Smalruby3::Sprite would lose the superclass after round-trip, becoming just class Sprite1. This PR encodes the superclass in the @ruby:class comment using <=path format (with ::/ encoding) and decodes it back in the generator.

Changes Made

Converter (ruby-to-blocks-converter/index.js)

  • Added _constantNodeToPath() helper to extract superclass path from prism AST nodes
  • Modified visitClassNode() to extract and validate superclass
  • Stage class only accepts ::Smalruby3::Stage or Smalruby3::Stage as superclass
  • Superclass is encoded as <=path in @ruby:class comment (e.g., @ruby:class:<=//Smalruby3/Sprite)
  • Added invalidStageSuperclass error message

Generator (ruby-generator/index.js)

  • Modified _wrapWithClass() to parse <=path from comment attributes
  • Decodes / back to :: (leading //::) for Ruby output
  • Non-file output: uses explicit superclass or none
  • File output: uses explicit superclass or defaults to ::Smalruby3::Sprite

Test Coverage

  • 8 new converter unit tests (5 sprite + 3 stage superclass scenarios)
  • 10 new generator unit tests (superclass decoding and output)
  • 9 new round-trip tests (full Ruby → Blocks → Ruby preservation)

Implementation Steps

  • Phase 1: Converter — extract and encode superclass in comment
  • Phase 2: Generator — decode superclass from comment and output
  • Phase 3: Round-trip integration tests

Closes #289

🤖 Generated with Claude Code

takaokouji and others added 3 commits March 13, 2026 12:59
…onversion

Add superclass extraction from ClassNode and encode it in @ruby:class comment
using <=path format (:: replaced by /). Stage validates only ::Smalruby3::Stage
or Smalruby3::Stage as superclass.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Parse <=encoded_path from @ruby:class comment, decode / back to ::,
and output the superclass in class definition. Non-file output uses
explicit superclass or none; file output defaults to ::Smalruby3::Sprite.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Tests Ruby → Blocks → Ruby round-trip for all superclass variants:
::Smalruby3::Sprite, Smalruby3::Sprite, Foo, Sprite, no superclass,
and Stage with accepted/rejected superclasses.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link

@takaokouji takaokouji merged commit b21a390 into develop Mar 13, 2026
9 checks passed
@takaokouji takaokouji deleted the fix/preserve-class-inheritance branch March 13, 2026 04:11
github-actions bot pushed a commit that referenced this pull request Mar 13, 2026
…class-inheritance

fix: preserve class inheritance (superclass) during Ruby round-trip
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.

fix: preserve class inheritance (superclass) during Ruby round-trip

1 participant