Skip to content

Commit bc21c9f

Browse files
committed
Reverse-sync ruby/ruby and deprecate old fields
1 parent 75fd020 commit bc21c9f

File tree

146 files changed

+518
-473
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

146 files changed

+518
-473
lines changed

config.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,7 +1310,7 @@ nodes:
13101310
type: node?
13111311
- name: conditions
13121312
type: node[]
1313-
- name: consequent
1313+
- name: else_clause
13141314
type: node?
13151315
kind: ElseNode
13161316
- name: case_keyword_loc
@@ -1330,7 +1330,7 @@ nodes:
13301330
type: node?
13311331
- name: conditions
13321332
type: node[]
1333-
- name: consequent
1333+
- name: else_clause
13341334
type: node?
13351335
kind: ElseNode
13361336
- name: case_keyword_loc
@@ -2187,7 +2187,7 @@ nodes:
21872187
baz
21882188
^^^
21892189
end
2190-
- name: consequent
2190+
- name: subsequent
21912191
type: node?
21922192
kind:
21932193
- ElseNode
@@ -3448,7 +3448,7 @@ nodes:
34483448
- name: statements
34493449
type: node?
34503450
kind: StatementsNode
3451-
- name: consequent
3451+
- name: subsequent
34523452
type: node?
34533453
kind: RescueNode
34543454
comment: |
@@ -3703,7 +3703,7 @@ nodes:
37033703
37043704
unless cond then bar end
37053705
^^^
3706-
- name: consequent
3706+
- name: else_clause
37073707
type: node?
37083708
kind: ElseNode
37093709
comment: |

lib/prism/desugar_compiler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def compile
6060
location: node.location,
6161
body: [public_send(read_class, location: node.name_loc, **arguments)]
6262
),
63-
consequent: else_node(
63+
subsequent: else_node(
6464
location: node.location,
6565
else_keyword_loc: node.operator_loc,
6666
statements: statements_node(

lib/prism/node_ext.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,4 +460,49 @@ def operator_loc
460460
binary_operator_loc
461461
end
462462
end
463+
464+
class CaseMatchNode < Node
465+
# Returns the else clause of the case match node. This method is deprecated
466+
# in favor of #else_clause.
467+
def consequent
468+
deprecated("else_clause")
469+
else_clause
470+
end
471+
end
472+
473+
class CaseNode < Node
474+
# Returns the else clause of the case node. This method is deprecated in
475+
# favor of #else_clause.
476+
def consequent
477+
deprecated("else_clause")
478+
else_clause
479+
end
480+
end
481+
482+
class IfNode < Node
483+
# Returns the subsequent if/elsif/else clause of the if node. This method is
484+
# deprecated in favor of #subsequent.
485+
def consequent
486+
deprecated("subsequent")
487+
subsequent
488+
end
489+
end
490+
491+
class RescueNode < Node
492+
# Returns the subsequent rescue clause of the rescue node. This method is
493+
# deprecated in favor of #subsequent.
494+
def consequent
495+
deprecated("subsequent")
496+
subsequent
497+
end
498+
end
499+
500+
class UnlessNode < Node
501+
# Returns the else clause of the unless node. This method is deprecated in
502+
# favor of #else_clause.
503+
def consequent
504+
deprecated("else_clause")
505+
else_clause
506+
end
507+
end
463508
end

lib/prism/translation/parser/compiler.rb

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def visit_begin_node(node)
181181
if (rescue_clause = node.rescue_clause)
182182
begin
183183
find_start_offset = (rescue_clause.reference&.location || rescue_clause.exceptions.last&.location || rescue_clause.keyword_loc).end_offset
184-
find_end_offset = (rescue_clause.statements&.location&.start_offset || rescue_clause.consequent&.location&.start_offset || (find_start_offset + 1))
184+
find_end_offset = (rescue_clause.statements&.location&.start_offset || rescue_clause.subsequent&.location&.start_offset || (find_start_offset + 1))
185185

186186
rescue_bodies << builder.rescue_body(
187187
token(rescue_clause.keyword_loc),
@@ -191,7 +191,7 @@ def visit_begin_node(node)
191191
srange_find(find_start_offset, find_end_offset, [";"]),
192192
visit(rescue_clause.statements)
193193
)
194-
end until (rescue_clause = rescue_clause.consequent).nil?
194+
end until (rescue_clause = rescue_clause.subsequent).nil?
195195
end
196196

197197
begin_body =
@@ -410,8 +410,8 @@ def visit_case_node(node)
410410
token(node.case_keyword_loc),
411411
visit(node.predicate),
412412
visit_all(node.conditions),
413-
token(node.consequent&.else_keyword_loc),
414-
visit(node.consequent),
413+
token(node.else_clause&.else_keyword_loc),
414+
visit(node.else_clause),
415415
token(node.end_keyword_loc)
416416
)
417417
end
@@ -423,8 +423,8 @@ def visit_case_match_node(node)
423423
token(node.case_keyword_loc),
424424
visit(node.predicate),
425425
visit_all(node.conditions),
426-
token(node.consequent&.else_keyword_loc),
427-
visit(node.consequent),
426+
token(node.else_clause&.else_keyword_loc),
427+
visit(node.else_clause),
428428
token(node.end_keyword_loc)
429429
)
430430
end
@@ -858,8 +858,8 @@ def visit_if_node(node)
858858
visit(node.predicate),
859859
token(node.then_keyword_loc),
860860
visit(node.statements),
861-
token(node.consequent.else_keyword_loc),
862-
visit(node.consequent)
861+
token(node.subsequent.else_keyword_loc),
862+
visit(node.subsequent)
863863
)
864864
elsif node.if_keyword_loc.start_offset == node.location.start_offset
865865
builder.condition(
@@ -868,24 +868,24 @@ def visit_if_node(node)
868868
if node.then_keyword_loc
869869
token(node.then_keyword_loc)
870870
else
871-
srange_find(node.predicate.location.end_offset, (node.statements&.location || node.consequent&.location || node.end_keyword_loc).start_offset, [";"])
871+
srange_find(node.predicate.location.end_offset, (node.statements&.location || node.subsequent&.location || node.end_keyword_loc).start_offset, [";"])
872872
end,
873873
visit(node.statements),
874-
case node.consequent
874+
case node.subsequent
875875
when IfNode
876-
token(node.consequent.if_keyword_loc)
876+
token(node.subsequent.if_keyword_loc)
877877
when ElseNode
878-
token(node.consequent.else_keyword_loc)
878+
token(node.subsequent.else_keyword_loc)
879879
end,
880-
visit(node.consequent),
880+
visit(node.subsequent),
881881
if node.if_keyword != "elsif"
882882
token(node.end_keyword_loc)
883883
end
884884
)
885885
else
886886
builder.condition_mod(
887887
visit(node.statements),
888-
visit(node.consequent),
888+
visit(node.subsequent),
889889
token(node.if_keyword_loc),
890890
visit(node.predicate)
891891
)
@@ -1784,16 +1784,16 @@ def visit_unless_node(node)
17841784
if node.then_keyword_loc
17851785
token(node.then_keyword_loc)
17861786
else
1787-
srange_find(node.predicate.location.end_offset, (node.statements&.location || node.consequent&.location || node.end_keyword_loc).start_offset, [";"])
1787+
srange_find(node.predicate.location.end_offset, (node.statements&.location || node.else_clause&.location || node.end_keyword_loc).start_offset, [";"])
17881788
end,
1789-
visit(node.consequent),
1790-
token(node.consequent&.else_keyword_loc),
1789+
visit(node.else_clause),
1790+
token(node.else_clause&.else_keyword_loc),
17911791
visit(node.statements),
17921792
token(node.end_keyword_loc)
17931793
)
17941794
else
17951795
builder.condition_mod(
1796-
visit(node.consequent),
1796+
visit(node.else_clause),
17971797
visit(node.statements),
17981798
token(node.keyword_loc),
17991799
visit(node.predicate)

lib/prism/translation/ripper.rb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,8 +1273,8 @@ def visit_capture_pattern_node(node)
12731273
def visit_case_node(node)
12741274
predicate = visit(node.predicate)
12751275
clauses =
1276-
node.conditions.reverse_each.inject(visit(node.consequent)) do |consequent, condition|
1277-
on_when(*visit(condition), consequent)
1276+
node.conditions.reverse_each.inject(visit(node.else_clause)) do |current, condition|
1277+
on_when(*visit(condition), current)
12781278
end
12791279

12801280
bounds(node.location)
@@ -1286,8 +1286,8 @@ def visit_case_node(node)
12861286
def visit_case_match_node(node)
12871287
predicate = visit(node.predicate)
12881288
clauses =
1289-
node.conditions.reverse_each.inject(visit(node.consequent)) do |consequent, condition|
1290-
on_in(*visit(condition), consequent)
1289+
node.conditions.reverse_each.inject(visit(node.else_clause)) do |current, condition|
1290+
on_in(*visit(condition), current)
12911291
end
12921292

12931293
bounds(node.location)
@@ -1908,7 +1908,7 @@ def visit_if_node(node)
19081908
if node.then_keyword == "?"
19091909
predicate = visit(node.predicate)
19101910
truthy = visit(node.statements.body.first)
1911-
falsy = visit(node.consequent.statements.body.first)
1911+
falsy = visit(node.subsequent.statements.body.first)
19121912

19131913
bounds(node.location)
19141914
on_ifop(predicate, truthy, falsy)
@@ -1921,13 +1921,13 @@ def visit_if_node(node)
19211921
else
19221922
visit(node.statements)
19231923
end
1924-
consequent = visit(node.consequent)
1924+
subsequent = visit(node.subsequent)
19251925

19261926
bounds(node.location)
19271927
if node.if_keyword == "if"
1928-
on_if(predicate, statements, consequent)
1928+
on_if(predicate, statements, subsequent)
19291929
else
1930-
on_elsif(predicate, statements, consequent)
1930+
on_elsif(predicate, statements, subsequent)
19311931
end
19321932
else
19331933
statements = visit(node.statements.body.first)
@@ -1960,7 +1960,7 @@ def visit_implicit_rest_node(node)
19601960
# ^^^^^^^^^^^^^^^^^^^^^
19611961
def visit_in_node(node)
19621962
# This is a special case where we're not going to call on_in directly
1963-
# because we don't have access to the consequent. Instead, we'll return
1963+
# because we don't have access to the subsequent. Instead, we'll return
19641964
# the component parts and let the parent node handle it.
19651965
pattern = visit_pattern_node(node.pattern)
19661966
statements =
@@ -2808,10 +2808,10 @@ def visit_rescue_node(node)
28082808
visit(node.statements)
28092809
end
28102810

2811-
consequent = visit(node.consequent)
2811+
subsequent = visit(node.subsequent)
28122812

28132813
bounds(node.location)
2814-
on_rescue(exceptions, reference, statements, consequent)
2814+
on_rescue(exceptions, reference, statements, subsequent)
28152815
end
28162816

28172817
# def foo(*bar); end
@@ -3132,10 +3132,10 @@ def visit_unless_node(node)
31323132
else
31333133
visit(node.statements)
31343134
end
3135-
consequent = visit(node.consequent)
3135+
else_clause = visit(node.else_clause)
31363136

31373137
bounds(node.location)
3138-
on_unless(predicate, statements, consequent)
3138+
on_unless(predicate, statements, else_clause)
31393139
else
31403140
statements = visit(node.statements.body.first)
31413141
predicate = visit(node.predicate)
@@ -3176,7 +3176,7 @@ def visit_until_node(node)
31763176
# ^^^^^^^^^^^^^
31773177
def visit_when_node(node)
31783178
# This is a special case where we're not going to call on_when directly
3179-
# because we don't have access to the consequent. Instead, we'll return
3179+
# because we don't have access to the subsequent. Instead, we'll return
31803180
# the component parts and let the parent node handle it.
31813181
conditions = visit_arguments(node.conditions)
31823182
statements =

lib/prism/translation/ruby_parser.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def visit_begin_node(node)
147147
end
148148

149149
current = node.rescue_clause
150-
until (current = current.consequent).nil?
150+
until (current = current.subsequent).nil?
151151
result << visit(current)
152152
end
153153
end
@@ -347,13 +347,13 @@ def visit_capture_pattern_node(node)
347347
# case foo; when bar; end
348348
# ^^^^^^^^^^^^^^^^^^^^^^^
349349
def visit_case_node(node)
350-
s(node, :case, visit(node.predicate)).concat(visit_all(node.conditions)) << visit(node.consequent)
350+
s(node, :case, visit(node.predicate)).concat(visit_all(node.conditions)) << visit(node.else_clause)
351351
end
352352

353353
# case foo; in bar; end
354354
# ^^^^^^^^^^^^^^^^^^^^^
355355
def visit_case_match_node(node)
356-
s(node, :case, visit(node.predicate)).concat(visit_all(node.conditions)) << visit(node.consequent)
356+
s(node, :case, visit(node.predicate)).concat(visit_all(node.conditions)) << visit(node.else_clause)
357357
end
358358

359359
# class Foo; end
@@ -700,7 +700,7 @@ def visit_hash_pattern_node(node)
700700
# foo ? bar : baz
701701
# ^^^^^^^^^^^^^^^
702702
def visit_if_node(node)
703-
s(node, :if, visit(node.predicate), visit(node.statements), visit(node.consequent))
703+
s(node, :if, visit(node.predicate), visit(node.statements), visit(node.subsequent))
704704
end
705705

706706
# 1i
@@ -1470,7 +1470,7 @@ def visit_undef_node(node)
14701470
# bar unless foo
14711471
# ^^^^^^^^^^^^^^
14721472
def visit_unless_node(node)
1473-
s(node, :if, visit(node.predicate), visit(node.consequent), visit(node.statements))
1473+
s(node, :if, visit(node.predicate), visit(node.else_clause), visit(node.statements))
14741474
end
14751475

14761476
# until foo; bar end

0 commit comments

Comments
 (0)