Skip to content

Commit

Permalink
Implement When Node locations
Browse files Browse the repository at this point in the history
  • Loading branch information
ydah committed Sep 21, 2024
1 parent e8ae7f4 commit 5d397d3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
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

0 comments on commit 5d397d3

Please sign in to comment.