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

Commit 0bdddcc

Browse files
committed
Fold Return0 into Return
1 parent 0059a82 commit 0bdddcc

File tree

6 files changed

+16
-51
lines changed

6 files changed

+16
-51
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
1717
- `Dot2` and `Dot3` are no longer nodes. Instead they have become a single new `RangeLiteral` node. This node looks the same as `Dot2` and `Dot3`, except that it additionally has an `operator` field that contains the operator that created the node. Consequently, the `visit_dot2` and `visit_dot3` methods have been removed from the visitor interface. If you were previously using these methods, you should now use `visit_range_literal` instead.
1818
- `DefEndless` and `Defs` have both been folded into the `Def` node. The `Def` node now has the `target` and `operator` fields which originally came from `Defs` which can both be `nil`. It also now has an `endless?` method on it to tell if the original node was found in the endless form. Finally the `bodystmt` field can now either be a `BodyStmt` as it was or any other kind of node since that was the body of the `DefEndless` node. The `visit_defs` and `visit_def_endless` methods on the visitor have therefore been removed.
1919
- `DoBlock` and `BraceBlock` have now been folded into a `Block` node. The `Block` node now has a `keywords?` method on it that returns true if the block was constructed with the `do`..`end` keywords. The `visit_do_block` and `visit_brace_block` methods on the visitor have therefore been removed and replaced with the `visit_block` method.
20+
- `Return0` is no longer a node. Instead if has been folded into the `Return` node. The `Return` node can now have its `arguments` field be `nil`. Consequently, the `visit_return0` method has been removed from the visitor interface. If you were previously using this method, you should now use `visit_return` instead.
2021
- The `ZSuper` node no longer has a `value` field associated with it (which was always a "super" string literal).
2122

2223
## [4.3.0] - 2022-10-28

lib/syntax_tree/node.rb

Lines changed: 12 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1975,6 +1975,13 @@ def initialize(keyword, node)
19751975
end
19761976

19771977
def format(q)
1978+
# If there are no arguments associated with this flow control, then we can
1979+
# safely just print the keyword and return.
1980+
if node.arguments.nil?
1981+
q.text(keyword)
1982+
return
1983+
end
1984+
19781985
q.group do
19791986
q.text(keyword)
19801987

@@ -5077,8 +5084,8 @@ def call(q, node)
50775084
def ternaryable?(statement)
50785085
case statement
50795086
when Alias, Assign, Break, Command, CommandCall, Heredoc, If, IfOp,
5080-
Lambda, MAssign, Next, OpAssign, RescueMod, Return, Return0, Super,
5081-
Undef, Unless, Until, VoidStmt, While, Yield, ZSuper
5087+
Lambda, MAssign, Next, OpAssign, RescueMod, Return, Super, Undef,
5088+
Unless, Until, VoidStmt, While, Yield, ZSuper
50825089
# This is a list of nodes that should not be allowed to be a part of a
50835090
# ternary clause.
50845091
false
@@ -5351,8 +5358,8 @@ def deconstruct_keys(_keys)
53515358
def format(q)
53525359
force_flat = [
53535360
Alias, Assign, Break, Command, CommandCall, Heredoc, If, IfOp, Lambda,
5354-
MAssign, Next, OpAssign, RescueMod, Return, Return0, Super, Undef,
5355-
Unless, VoidStmt, Yield, ZSuper
5361+
MAssign, Next, OpAssign, RescueMod, Return, Super, Undef, Unless,
5362+
VoidStmt, Yield, ZSuper
53565363
]
53575364

53585365
if q.parent.is_a?(Paren) || force_flat.include?(truthy.class) ||
@@ -7739,7 +7746,7 @@ def format(q)
77397746
# return value
77407747
#
77417748
class Return < Node
7742-
# [Args] the arguments being passed to the keyword
7749+
# [nil | Args] the arguments being passed to the keyword
77437750
attr_reader :arguments
77447751

77457752
# [Array[ Comment | EmbDoc ]] the comments attached to this node
@@ -7770,42 +7777,6 @@ def format(q)
77707777
end
77717778
end
77727779

7773-
# Return0 represents the bare +return+ keyword with no arguments.
7774-
#
7775-
# return
7776-
#
7777-
class Return0 < Node
7778-
# [String] the value of the keyword
7779-
attr_reader :value
7780-
7781-
# [Array[ Comment | EmbDoc ]] the comments attached to this node
7782-
attr_reader :comments
7783-
7784-
def initialize(value:, location:)
7785-
@value = value
7786-
@location = location
7787-
@comments = []
7788-
end
7789-
7790-
def accept(visitor)
7791-
visitor.visit_return0(self)
7792-
end
7793-
7794-
def child_nodes
7795-
[]
7796-
end
7797-
7798-
alias deconstruct child_nodes
7799-
7800-
def deconstruct_keys(_keys)
7801-
{ value: value, location: location, comments: comments }
7802-
end
7803-
7804-
def format(q)
7805-
q.text(value)
7806-
end
7807-
end
7808-
78097780
# RParen represents the use of a right parenthesis, i.e., +)+.
78107781
class RParen < Node
78117782
# [String] the parenthesis

lib/syntax_tree/parser.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3084,11 +3084,11 @@ def on_return(arguments)
30843084
end
30853085

30863086
# :call-seq:
3087-
# on_return0: () -> Return0
3087+
# on_return0: () -> Return
30883088
def on_return0
30893089
keyword = consume_keyword(:return)
30903090

3091-
Return0.new(value: keyword.value, location: keyword.location)
3091+
Return.new(arguments: nil, location: keyword.location)
30923092
end
30933093

30943094
# :call-seq:

lib/syntax_tree/visitor.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,6 @@ class Visitor < BasicVisitor
338338
# Visit a Return node.
339339
alias visit_return visit_child_nodes
340340

341-
# Visit a Return0 node.
342-
alias visit_return0 visit_child_nodes
343-
344341
# Visit a RParen node.
345342
alias visit_rparen visit_child_nodes
346343

lib/syntax_tree/visitor/field_visitor.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -789,10 +789,6 @@ def visit_return(node)
789789
end
790790
end
791791

792-
def visit_return0(node)
793-
visit_token(node, "return0")
794-
end
795-
796792
def visit_rparen(node)
797793
node(node, "rparen") { field("value", node.value) }
798794
end

test/node_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ def test_return
841841
end
842842

843843
def test_return0
844-
assert_node(Return0, "return")
844+
assert_node(Return, "return")
845845
end
846846

847847
def test_sclass

0 commit comments

Comments
 (0)