From 68186c69260da9c3cb993781d0a5a26672e06c49 Mon Sep 17 00:00:00 2001 From: ydah Date: Mon, 30 Sep 2024 15:09:28 +0900 Subject: [PATCH] Implement Index Operator Write Node locations --- lib/ast_to_prism/parser.rb | 25 +++++++++++++------------ spec/basic_spec.rb | 4 ---- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/lib/ast_to_prism/parser.rb b/lib/ast_to_prism/parser.rb index 9041bb5..6571e42 100644 --- a/lib/ast_to_prism/parser.rb +++ b/lib/ast_to_prism/parser.rb @@ -1242,6 +1242,7 @@ def convert_node(node, block: nil) not_supported(node) when :OP_ASGN1 nd_recv, nd_mid, nd_index, nd_rvalue = node.children + loc, call_operator_loc, opening_loc, closing_loc, binary_operator_loc = node.locations receiver = convert_node(nd_recv) arguments, _ = convert_arguments(nd_index) # NOTE: Can block not be nil? @@ -1250,18 +1251,18 @@ def convert_node(node, block: nil) value = convert_node(nd_rvalue) Prism::IndexOperatorWriteNode.new( - source, # source - 0, # flags - receiver, # receiver - null_location, # call_operator_loc - null_location, # opening_loc - arguments, # arguments - null_location, # closing_loc - block, # block - binary_operator, # binary_operator - null_location, # binary_operator_loc - value, # value - location(node) # location + source, # source + 0, # flags + receiver, # receiver + location(call_operator_loc), # call_operator_loc + location(opening_loc), # opening_loc + arguments, # arguments + location(closing_loc), # closing_loc + block, # block + binary_operator, # binary_operator + location(binary_operator_loc), # binary_operator_loc + value, # value + location(loc) # location ) when :OP_ASGN2 nd_recv, nd_aid, nd_vid, nd_mid, nd_value = node.children diff --git a/spec/basic_spec.rb b/spec/basic_spec.rb index fb3462f..1c48cbc 100644 --- a/spec/basic_spec.rb +++ b/spec/basic_spec.rb @@ -651,16 +651,12 @@ def test_code(code) describe "array assignment with operator (OP_ASGN1)" do it "tests" do - pending "IndexOperatorWriteNode locations are not supported" - test_code(<<~CODE) ary[1] += foo CODE end it "tests" do - pending "IndexOperatorWriteNode locations are not supported" - test_code(<<~CODE) ary[1, 2] += foo CODE