Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 35f21a7

Browse files
committed
Remmove visit_lambda_var method from visitors
1 parent 6f26a47 commit 35f21a7

File tree

4 files changed

+18
-57
lines changed

4 files changed

+18
-57
lines changed

lib/syntax_tree/field_visitor.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -526,14 +526,6 @@ def visit_lambda(node)
526526
end
527527
end
528528

529-
def visit_lambda_var(node)
530-
node(node, "lambda_var") do
531-
field("params", node.params)
532-
list("locals", node.locals) if node.locals.any?
533-
comments(node)
534-
end
535-
end
536-
537529
def visit_lbrace(node)
538530
visit_token(node, "lbrace")
539531
end

lib/syntax_tree/mutation_visitor.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -500,11 +500,6 @@ def visit_lambda(node)
500500
)
501501
end
502502

503-
# Visit a LambdaVar node.
504-
def visit_lambda_var(node)
505-
node.copy(params: visit(node.params), locals: visit_all(node.locals))
506-
end
507-
508503
# Visit a LBrace node.
509504
def visit_lbrace(node)
510505
node.copy

lib/syntax_tree/translation/parser.rb

Lines changed: 18 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -546,13 +546,12 @@ def visit_block_var(node)
546546
)
547547
end
548548

549-
params = node.params
550549
children =
551-
if ::Parser::Builders::Default.emit_procarg0 && node.arg0?
550+
if ::Parser::Builders::Default.emit_procarg0 && node.arg0? && node.pipe?
552551
# There is a special node type in the parser gem for when a single
553552
# required parameter to a block would potentially be expanded
554553
# automatically. We handle that case here.
555-
required = params.requireds.first
554+
required = node.params.requireds.first
556555
procarg0 =
557556
if ::Parser::Builders::Default.emit_arg_inside_procarg0 &&
558557
required.is_a?(Ident)
@@ -577,18 +576,23 @@ def visit_block_var(node)
577576

578577
[procarg0]
579578
else
580-
visit(params).children
579+
visit(node.params).children
581580
end
582581

583-
s(
584-
:args,
585-
children + shadowargs,
586-
smap_collection(
587-
srange_length(node.start_char, 1),
588-
srange_length(node.end_char, -1),
589-
srange_node(node)
590-
)
591-
)
582+
location =
583+
if node.start_char == node.end_char
584+
smap_collection_bare(nil)
585+
elsif buffer.source[node.start_char - 1] == "("
586+
smap_collection(
587+
srange_length(node.start_char, 1),
588+
srange_length(node.end_char, -1),
589+
srange_node(node)
590+
)
591+
else
592+
smap_collection_bare(srange_node(node))
593+
end
594+
595+
s(:args, children + shadowargs, location)
592596
end
593597

594598
# Visit a BodyStmt node.
@@ -1520,7 +1524,7 @@ def visit_label(node)
15201524
# Visit a Lambda node.
15211525
def visit_lambda(node)
15221526
args =
1523-
node.params.is_a?(LambdaVar) ? node.params : node.params.contents
1527+
node.params.is_a?(BlockVar) ? node.params : node.params.contents
15241528
args_node = visit(args)
15251529

15261530
type = :block
@@ -1559,33 +1563,6 @@ def visit_lambda(node)
15591563
)
15601564
end
15611565

1562-
# Visit a LambdaVar node.
1563-
def visit_lambda_var(node)
1564-
shadowargs =
1565-
node.locals.map do |local|
1566-
s(
1567-
:shadowarg,
1568-
[local.value.to_sym],
1569-
smap_variable(srange_node(local), srange_node(local))
1570-
)
1571-
end
1572-
1573-
location =
1574-
if node.start_char == node.end_char
1575-
smap_collection_bare(nil)
1576-
elsif buffer.source[node.start_char - 1] == "("
1577-
smap_collection(
1578-
srange_length(node.start_char, 1),
1579-
srange_length(node.end_char, -1),
1580-
srange_node(node)
1581-
)
1582-
else
1583-
smap_collection_bare(srange_node(node))
1584-
end
1585-
1586-
s(:args, visit(node.params).children + shadowargs, location)
1587-
end
1588-
15891566
# Visit an MAssign node.
15901567
def visit_massign(node)
15911568
s(

lib/syntax_tree/visitor.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,6 @@ class Visitor < BasicVisitor
218218
# Visit a Lambda node.
219219
alias visit_lambda visit_child_nodes
220220

221-
# Visit a LambdaVar node.
222-
alias visit_lambda_var visit_child_nodes
223-
224221
# Visit a LBrace node.
225222
alias visit_lbrace visit_child_nodes
226223

0 commit comments

Comments
 (0)