Skip to content

Commit 832289f

Browse files
committed
Update yarv compiler and decompiler to stop using Elsif node
1 parent 404e5fd commit 832289f

File tree

3 files changed

+3
-12
lines changed

3 files changed

+3
-12
lines changed

Diff for: CHANGELOG.md

+1
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

1818
- Fixed the AST output by adding blocks to `Command` and `CommandCall` nodes in the `FieldVisitor`.
1919
- Fixed the location of lambda local variables (e.g., `->(; a) {}`).
20+
- The `Elsif` node has been folded into `IfNode`. A `keyword` field has been added to `IfNode` specifying if the node represents an `if` or `elsif`.
2021

2122
## [6.0.1] - 2023-02-26
2223

Diff for: lib/syntax_tree/yarv/compiler.rb

+1-11
Original file line numberDiff line numberDiff line change
@@ -916,17 +916,6 @@ def visit_else(node)
916916
iseq.pop unless last_statement?
917917
end
918918

919-
def visit_elsif(node)
920-
visit_if(
921-
IfNode.new(
922-
predicate: node.predicate,
923-
statements: node.statements,
924-
consequent: node.consequent,
925-
location: node.location
926-
)
927-
)
928-
end
929-
930919
def visit_ensure(node)
931920
end
932921

@@ -1054,6 +1043,7 @@ def visit_if(node)
10541043
def visit_if_op(node)
10551044
visit_if(
10561045
IfNode.new(
1046+
keyword: Kw.new(value: "if", location: Location.default),
10571047
predicate: node.predicate,
10581048
statements:
10591049
Statements.new(body: [node.truthy], location: Location.default),

Diff for: lib/syntax_tree/yarv/decompiler.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def decompile(iseq)
7777
Next(Args([]))
7878
]
7979

80-
clause << IfNode(clause.pop, Statements(body), nil)
80+
clause << IfNode(Kw("if"), clause.pop, Statements(body), nil)
8181
when Dup
8282
clause << clause.last
8383
when DupHash

0 commit comments

Comments
 (0)