Skip to content
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

Introduce NestTopLevelMembers rewriter #352

Merged
merged 1 commit into from
Aug 6, 2024
Merged

Conversation

Morriar
Copy link
Collaborator

@Morriar Morriar commented Aug 6, 2024

RBS doesn't support method definitions at the top level:

rbs = RBS::Buffer.new(content: <<~RBS, name: "")
  def foo: -> void
RBS

RBS::Parser.parse_signature(rbs) # => Syntax error: cannot start a declaration, token=`def` (kDEF)

A trick we can play is to always rewrite the RBI file to nest all the top level members into an Object class so this:

def foo; end
attr_reader :bar

is rewritten to:

class Object
  def foo; end
  attr_reader :bar
end

Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
@Morriar Morriar added the feature New feature label Aug 6, 2024
@Morriar Morriar self-assigned this Aug 6, 2024
@Morriar Morriar requested a review from a team as a code owner August 6, 2024 16:47
@Morriar Morriar requested review from amomchilov and KaanOzkan August 6, 2024 16:47
@Morriar Morriar merged commit f8f3be0 into main Aug 6, 2024
8 checks passed
@Morriar Morriar deleted the at-top-level-rewriter branch August 6, 2024 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants