@@ -1614,15 +1614,23 @@ public RubyNode visitGlobalVarNode(GlobalVarParseNode node) {
1614
1614
public RubyNode visitHashNode (HashParseNode node ) {
1615
1615
final SourceIndexLength sourceSection = node .getPosition ();
1616
1616
1617
+ if (node .isEmpty ()) { // an empty Hash literal like h = {}
1618
+ final RubyNode ret = HashLiteralNode .create (language , RubyNode .EMPTY_ARRAY );
1619
+ ret .unsafeSetSourceSection (sourceSection );
1620
+ return addNewlineIfNeeded (node , ret );
1621
+ }
1622
+
1617
1623
final List <RubyNode > hashConcats = new ArrayList <>();
1618
1624
final List <RubyNode > keyValues = new ArrayList <>();
1619
1625
1620
1626
for (ParseNodeTuple pair : node .getPairs ()) {
1621
1627
if (pair .getKey () == null ) {
1622
1628
// This null case is for splats {a: 1, **{b: 2}, c: 3}
1623
- final RubyNode hashLiteralSoFar = HashLiteralNode
1624
- .create (language , keyValues .toArray (RubyNode .EMPTY_ARRAY ));
1625
- hashConcats .add (hashLiteralSoFar );
1629
+ if (!keyValues .isEmpty ()) {
1630
+ final RubyNode hashLiteralSoFar = HashLiteralNode
1631
+ .create (language , keyValues .toArray (RubyNode .EMPTY_ARRAY ));
1632
+ hashConcats .add (hashLiteralSoFar );
1633
+ }
1626
1634
hashConcats .add (HashCastNodeGen .create (pair .getValue ().accept (this )));
1627
1635
keyValues .clear ();
1628
1636
} else {
@@ -1636,8 +1644,10 @@ public RubyNode visitHashNode(HashParseNode node) {
1636
1644
}
1637
1645
}
1638
1646
1639
- final RubyNode hashLiteralSoFar = HashLiteralNode .create (language , keyValues .toArray (RubyNode .EMPTY_ARRAY ));
1640
- hashConcats .add (hashLiteralSoFar );
1647
+ if (!keyValues .isEmpty ()) {
1648
+ final RubyNode hashLiteralSoFar = HashLiteralNode .create (language , keyValues .toArray (RubyNode .EMPTY_ARRAY ));
1649
+ hashConcats .add (hashLiteralSoFar );
1650
+ }
1641
1651
1642
1652
if (hashConcats .size () == 1 ) {
1643
1653
final RubyNode ret = hashConcats .get (0 );
0 commit comments