From efd798ba24f828a9b5fbb76d483cacd7753741ea Mon Sep 17 00:00:00 2001 From: ydah Date: Sat, 21 Sep 2024 09:20:33 +0900 Subject: [PATCH] Implement And/Or Node locations --- lib/ast_to_prism/parser.rb | 24 ++++++++++++------------ spec/basic_spec.rb | 8 -------- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/lib/ast_to_prism/parser.rb b/lib/ast_to_prism/parser.rb index 9041bb5..5667b71 100644 --- a/lib/ast_to_prism/parser.rb +++ b/lib/ast_to_prism/parser.rb @@ -1176,25 +1176,25 @@ def convert_node(node, block: nil) ) when :AND nd_1st, nd_2nd = node.children + loc, operator_loc = node.locations - # (source, left, right, operator_loc, location) Prism::AndNode.new( - source, - convert_node(nd_1st), - convert_node(nd_2nd), - null_location, - location(node) + source, # source + convert_node(nd_1st), # left + convert_node(nd_2nd), # right + location(operator_loc), # operator_loc + location(loc), # location ) when :OR nd_1st, nd_2nd = node.children + loc, operator_loc = node.locations - # (source, left, right, operator_loc, location) Prism::OrNode.new( - source, - convert_node(nd_1st), - convert_node(nd_2nd), - null_location, - location(node) + source, # source + convert_node(nd_1st), # left + convert_node(nd_2nd), # right + location(operator_loc), # operator_loc + location(loc), # location ) when :MASGN not_supported(node) diff --git a/spec/basic_spec.rb b/spec/basic_spec.rb index fb3462f..8238a7e 100644 --- a/spec/basic_spec.rb +++ b/spec/basic_spec.rb @@ -897,28 +897,20 @@ def test_code(code) describe "and" do it "tests" do - pending "operator_loc is not supported" - test_code("1 && 2") end it "tests" do - pending "operator_loc is not supported" - test_code("1 and 2") end end describe "or" do it "tests" do - pending "operator_loc is not supported" - test_code("1 || 2") end it "tests" do - pending "operator_loc is not supported" - test_code("1 or 2") end end