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

Implement YieldNode #23

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/ast_to_prism/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
42 changes: 42 additions & 0 deletions spec/basic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 12 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down