Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remmove visit_lambda_var method from visitors
  • Loading branch information
egiurleo committed Mar 23, 2023
commit 2779aacd55d74ca5e4cf0cf66055ad51ecf7f805
8 changes: 0 additions & 8 deletions lib/syntax_tree/field_visitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -526,14 +526,6 @@ def visit_lambda(node)
end
end

def visit_lambda_var(node)
node(node, "lambda_var") do
field("params", node.params)
list("locals", node.locals) if node.locals.any?
comments(node)
end
end

def visit_lbrace(node)
visit_token(node, "lbrace")
end
Expand Down
5 changes: 0 additions & 5 deletions lib/syntax_tree/mutation_visitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -500,11 +500,6 @@ def visit_lambda(node)
)
end

# Visit a LambdaVar node.
def visit_lambda_var(node)
node.copy(params: visit(node.params), locals: visit_all(node.locals))
end

# Visit a LBrace node.
def visit_lbrace(node)
node.copy
Expand Down
60 changes: 19 additions & 41 deletions lib/syntax_tree/translation/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -546,13 +546,13 @@ def visit_block_var(node)
)
end

params = node.params
children =
if ::Parser::Builders::Default.emit_procarg0 && node.arg0?
if ::Parser::Builders::Default.emit_procarg0 && node.arg0? &&
node.pipe?
# There is a special node type in the parser gem for when a single
# required parameter to a block would potentially be expanded
# automatically. We handle that case here.
required = params.requireds.first
required = node.params.requireds.first
procarg0 =
if ::Parser::Builders::Default.emit_arg_inside_procarg0 &&
required.is_a?(Ident)
Expand All @@ -577,18 +577,23 @@ def visit_block_var(node)

[procarg0]
else
visit(params).children
visit(node.params).children
end

s(
:args,
children + shadowargs,
smap_collection(
srange_length(node.start_char, 1),
srange_length(node.end_char, -1),
srange_node(node)
)
)
location =
if node.start_char == node.end_char
smap_collection_bare(nil)
elsif buffer.source[node.start_char - 1] == "("
smap_collection(
srange_length(node.start_char, 1),
srange_length(node.end_char, -1),
srange_node(node)
)
else
smap_collection_bare(srange_node(node))
end

s(:args, children + shadowargs, location)
end

# Visit a BodyStmt node.
Expand Down Expand Up @@ -1520,7 +1525,7 @@ def visit_label(node)
# Visit a Lambda node.
def visit_lambda(node)
args =
node.params.is_a?(LambdaVar) ? node.params : node.params.contents
node.params.is_a?(BlockVar) ? node.params : node.params.contents
args_node = visit(args)

type = :block
Expand Down Expand Up @@ -1559,33 +1564,6 @@ def visit_lambda(node)
)
end

# Visit a LambdaVar node.
def visit_lambda_var(node)
shadowargs =
node.locals.map do |local|
s(
:shadowarg,
[local.value.to_sym],
smap_variable(srange_node(local), srange_node(local))
)
end

location =
if node.start_char == node.end_char
smap_collection_bare(nil)
elsif buffer.source[node.start_char - 1] == "("
smap_collection(
srange_length(node.start_char, 1),
srange_length(node.end_char, -1),
srange_node(node)
)
else
smap_collection_bare(srange_node(node))
end

s(:args, visit(node.params).children + shadowargs, location)
end

# Visit an MAssign node.
def visit_massign(node)
s(
Expand Down
3 changes: 0 additions & 3 deletions lib/syntax_tree/visitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,6 @@ class Visitor < BasicVisitor
# Visit a Lambda node.
alias visit_lambda visit_child_nodes

# Visit a LambdaVar node.
alias visit_lambda_var visit_child_nodes

# Visit a LBrace node.
alias visit_lbrace visit_child_nodes

Expand Down