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 When Node locations #58

Merged
merged 1 commit into from
Oct 2, 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
7 changes: 4 additions & 3 deletions lib/ast_to_prism/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -589,18 +589,19 @@ def convert_case_body(node)

while node do
nd_head, nd_body, nd_next = node.children
loc, keyword_loc, then_keyword_loc = node.locations

cond = nd_head.children[0...-1].map do |n|
convert_node(n)
end

conditions << Prism::WhenNode.new(
source, # source
null_location, # keyword_loc
location(keyword_loc), # keyword_loc
cond, # conditions
null_location, # then_keyword_loc
location(then_keyword_loc), # then_keyword_loc
convert_case_statements(nd_body), # statements
location(node) # location
location(loc) # location
)

if nd_next&.type == :WHEN
Expand Down
20 changes: 10 additions & 10 deletions spec/basic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2462,7 +2462,7 @@ def m

describe "case with head" do
it "tests" do
pending "WhenNode locations are not supported"
pending "CaseNode locations are not supported"

test_code(<<~CODE)
case x
Expand All @@ -2472,7 +2472,7 @@ def m
end

it "tests" do
pending "WhenNode locations are not supported"
pending "CaseNode locations are not supported"

test_code(<<~CODE)
case x
Expand All @@ -2482,7 +2482,7 @@ def m
end

it "tests" do
pending "WhenNode locations and ElseNode locations are not supported"
pending "ElseNode locations are not supported"

test_code(<<~CODE)
case x
Expand All @@ -2493,7 +2493,7 @@ def m
end

it "tests" do
pending "WhenNode locations are not supported"
pending "CaseNode locations are not supported"

test_code(<<~CODE)
case x
Expand All @@ -2506,7 +2506,7 @@ def m
end

it "tests" do
pending "WhenNode locations and ElseNode locations are not supported"
pending "ElseNode locations are not supported"

test_code(<<~CODE)
case x
Expand All @@ -2523,7 +2523,7 @@ def m

describe "case with no head" do
it "tests" do
pending "WhenNode locations locations are not supported"
pending "CaseNode locations are not supported"

test_code(<<~CODE)
case
Expand All @@ -2533,7 +2533,7 @@ def m
end

it "tests" do
pending "WhenNode locations locations are not supported"
pending "CaseNode locations are not supported"

test_code(<<~CODE)
case
Expand All @@ -2543,7 +2543,7 @@ def m
end

it "tests" do
pending "WhenNode locations and ElseNode locations are not supported"
pending "ElseNode locations are not supported"

test_code(<<~CODE)
case
Expand All @@ -2554,7 +2554,7 @@ def m
end

it "tests" do
pending "WhenNode locations locations are not supported"
pending "CaseNode locations are not supported"

test_code(<<~CODE)
case
Expand All @@ -2567,7 +2567,7 @@ def m
end

it "tests" do
pending "WhenNode locations and ElseNode locations are not supported"
pending "ElseNode locations are not supported"

test_code(<<~CODE)
case
Expand Down