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

Commit 7f04f53

Browse files
committed
Fold Yield0 into Yield
1 parent 672abb2 commit 7f04f53

File tree

6 files changed

+12
-49
lines changed

6 files changed

+12
-49
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
1212
- `IfMod` and `UnlessMod` are no longer nodes. Instead, they have been folded into `If` and `Unless`, respectively. The `If` and `Unless` nodes now have a `modifier?` method to tell you if they were original found in the modifier form.
1313
- `WhileMod` and `UntilMod` are no longer nodes. Instead, they have been folded into `While` and `Until`, respectively. The `While` and `Until` nodes now have a `modifier?` method to tell you if they were originally found in the modifier form.
1414
- `VarAlias` is no longer a node. Instead it has been folded into the `Alias` node. The `Alias` node now has a `var_alias?` method to tell you if it is aliasing a global variable.
15+
- `Yield0` is no longer a node. Instead if has been folded into the `Yield` node. The `Yield` node can now have its `arguments` field be `nil`.
1516

1617
## [4.3.0] - 2022-10-28
1718

lib/syntax_tree/node.rb

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5403,7 +5403,7 @@ def ternaryable?(statement)
54035403
case statement
54045404
when Alias, Assign, Break, Command, CommandCall, Heredoc, If, IfOp,
54055405
Lambda, MAssign, Next, OpAssign, RescueMod, Return, Return0, Super,
5406-
Undef, Unless, Until, VoidStmt, While, Yield, Yield0, ZSuper
5406+
Undef, Unless, Until, VoidStmt, While, Yield, ZSuper
54075407
# This is a list of nodes that should not be allowed to be a part of a
54085408
# ternary clause.
54095409
false
@@ -5677,7 +5677,7 @@ def format(q)
56775677
force_flat = [
56785678
Alias, Assign, Break, Command, CommandCall, Heredoc, If, IfOp, Lambda,
56795679
MAssign, Next, OpAssign, RescueMod, Return, Return0, Super, Undef,
5680-
Unless, VoidStmt, Yield, Yield0, ZSuper
5680+
Unless, VoidStmt, Yield, ZSuper
56815681
]
56825682

56835683
if q.parent.is_a?(Paren) || force_flat.include?(truthy.class) ||
@@ -10101,7 +10101,7 @@ def format(q)
1010110101
# yield value
1010210102
#
1010310103
class Yield < Node
10104-
# [Args | Paren] the arguments passed to the yield
10104+
# [nil | Args | Paren] the arguments passed to the yield
1010510105
attr_reader :arguments
1010610106

1010710107
# [Array[ Comment | EmbDoc ]] the comments attached to this node
@@ -10128,6 +10128,11 @@ def deconstruct_keys(_keys)
1012810128
end
1012910129

1013010130
def format(q)
10131+
if arguments.nil?
10132+
q.text("yield")
10133+
return
10134+
end
10135+
1013110136
q.group do
1013210137
q.text("yield")
1013310138

@@ -10146,42 +10151,6 @@ def format(q)
1014610151
end
1014710152
end
1014810153

10149-
# Yield0 represents the bare +yield+ keyword with no arguments.
10150-
#
10151-
# yield
10152-
#
10153-
class Yield0 < Node
10154-
# [String] the value of the keyword
10155-
attr_reader :value
10156-
10157-
# [Array[ Comment | EmbDoc ]] the comments attached to this node
10158-
attr_reader :comments
10159-
10160-
def initialize(value:, location:)
10161-
@value = value
10162-
@location = location
10163-
@comments = []
10164-
end
10165-
10166-
def accept(visitor)
10167-
visitor.visit_yield0(self)
10168-
end
10169-
10170-
def child_nodes
10171-
[]
10172-
end
10173-
10174-
alias deconstruct child_nodes
10175-
10176-
def deconstruct_keys(_keys)
10177-
{ value: value, location: location, comments: comments }
10178-
end
10179-
10180-
def format(q)
10181-
q.text(value)
10182-
end
10183-
end
10184-
1018510154
# ZSuper represents the bare +super+ keyword with no arguments.
1018610155
#
1018710156
# super

lib/syntax_tree/parser.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3896,11 +3896,11 @@ def on_yield(arguments)
38963896
end
38973897

38983898
# :call-seq:
3899-
# on_yield0: () -> Yield0
3899+
# on_yield0: () -> Yield
39003900
def on_yield0
39013901
keyword = consume_keyword(:yield)
39023902

3903-
Yield0.new(value: keyword.value, location: keyword.location)
3903+
Yield.new(arguments: nil, location: keyword.location)
39043904
end
39053905

39063906
# :call-seq:

lib/syntax_tree/visitor.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,9 +467,6 @@ class Visitor < BasicVisitor
467467
# Visit a Yield node.
468468
alias visit_yield visit_child_nodes
469469

470-
# Visit a Yield0 node.
471-
alias visit_yield0 visit_child_nodes
472-
473470
# Visit a ZSuper node.
474471
alias visit_zsuper visit_child_nodes
475472

lib/syntax_tree/visitor/field_visitor.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,10 +1060,6 @@ def visit_yield(node)
10601060
end
10611061
end
10621062

1063-
def visit_yield0(node)
1064-
visit_token(node, "yield0")
1065-
end
1066-
10671063
def visit_zsuper(node)
10681064
visit_token(node, "zsuper")
10691065
end

test/node_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ def test_yield
10131013
end
10141014

10151015
def test_yield0
1016-
assert_node(Yield0, "yield")
1016+
assert_node(Yield, "yield")
10171017
end
10181018

10191019
def test_zsuper

0 commit comments

Comments
 (0)