From 37aa267b2d6b9bbb3ed39f429310cf8861f9ce8d Mon Sep 17 00:00:00 2001 From: yui-knk Date: Mon, 8 Jul 2024 10:10:34 +0900 Subject: [PATCH] Implement YieldNode --- lib/ast_to_prism/parser.rb | 11 +++++++++- spec/basic_spec.rb | 42 ++++++++++++++++++++++++++++++++++++++ spec/spec_helper.rb | 12 +++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/lib/ast_to_prism/parser.rb b/lib/ast_to_prism/parser.rb index 36dad52..100bbc7 100644 --- a/lib/ast_to_prism/parser.rb +++ b/lib/ast_to_prism/parser.rb @@ -1263,7 +1263,16 @@ def convert_node(node, block: nil) location(node) # location ) when :YIELD - not_supported(node) + nd_head, = node.children + + Prism::YieldNode.new( + source, # source + null_location, # keyword_loc + null_location, # lparen_loc + convert_arguments(nd_head), # arguments + null_location, # rparen_loc + location(node) # location + ) when :LVAR nd_vid, = node.children diff --git a/spec/basic_spec.rb b/spec/basic_spec.rb index 8685d67..406592f 100644 --- a/spec/basic_spec.rb +++ b/spec/basic_spec.rb @@ -1637,6 +1637,48 @@ def m end end + describe "yield" do + it "tests" do + pending "YieldNode locations are not supported" + + test_code(<<~CODE) + def m + yield + end + CODE + end + + it "tests" do + pending "YieldNode locations are not supported" + + test_code(<<~CODE) + def m + yield() + end + CODE + end + + it "tests" do + pending "YieldNode locations are not supported" + + test_code(<<~CODE) + def m + yield 1, 2 + end + CODE + end + + it "tests" do + pending "YieldNode locations are not supported" + + test_code(<<~CODE) + def m + yield(1, 2) + end + CODE + end + end + describe "redo" do it "tests" do pending "opening_loc and closing_loc of BlockParametersNode are not supported" diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8f58bec..20f4ff9 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -414,6 +414,18 @@ def ===(other) } end + class YieldNode + prepend Module.new { + def ===(other) + super(other) && + self.location == other.location && + self.keyword_loc == other.keyword_loc && + self.lparen_loc == other.lparen_loc && + self.rparen_loc == other.rparen_loc + end + } + end + class ForNode prepend Module.new { def ===(other)