Skip to content

Commit

Permalink
Added key/value to kwoptarg
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBakerEffendi committed Oct 29, 2024
1 parent 5644676 commit d242866
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/ruby_ast_gen/node_handling.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module NodeHandling
CALLS = [:send, :csend]
DYNAMIC_LITERALS = [:dsym, :dstr]
CONTROL_KW = [:break, :next]
ARGUMENTS = [:arg, :restarg, :kwoptarg, :blockarg, :kwrestarg, :kwarg, :shadowarg, :kwnilarg]
ARGUMENTS = [:arg, :restarg, :blockarg, :kwrestarg, :kwarg, :shadowarg, :kwnilarg]
REFS = [:nth_ref, :back_ref]
FORWARD_ARGUMENTS = [:forward_args, :forwarded_args, :forward_arg]
ASSIGNMENTS = [:or_asgn, :and_asgn, :lvasgn, :ivasgn, :gvasgn, :cvasgn, :match_with_lvasgn]
Expand Down Expand Up @@ -177,7 +177,10 @@ def self.add_node_properties(node_type, base_map, file_path)
base_map[:lhs] = children[0]
base_map[:rhs] = children[1]
when *SINGLETONS
base_map[:value] = node_type
base_map[:value] = node_type
when :kwoptarg
base_map[:key] = children[0]
base_map[:value] = children[1]
when *LITERALS, *ARGUMENTS, *ACCESS, :match_rest
base_map[:value] = children[0]
when :cbase
Expand Down
10 changes: 10 additions & 0 deletions spec/ruby_ast_gen_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ def f(x)
code(<<-CODE)
def foo(x)
x += 1
end
CODE
ast = RubyAstGen::parse_file(temp_file.path, temp_name)
expect(ast).not_to be_nil
end

it "should create a function with a keyword option argument sucessfully" do
code(<<-CODE)
def foo(a, bar: "default")
puts(bar)
end
CODE
ast = RubyAstGen::parse_file(temp_file.path, temp_name)
Expand Down

0 comments on commit d242866

Please sign in to comment.