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

Commit 7c31d27

Browse files
committed
Allow Hash opening braces to have trailing comments.
1 parent be97d5b commit 7c31d27

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
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
- Comments can now be attached to the `case` keyword.
1313
- Remove escaped forward slashes from regular expression literals when converting to `%r`.
1414
- Allow arrays of `CHAR` nodes to be converted to `QWords` under certain conditions.
15+
- Allow `Hash` opening braces to have trailing comments.
1516

1617
### Changed
1718

lib/syntax_tree.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6096,6 +6096,9 @@ def on_gvar(value)
60966096
# { key => value }
60976097
#
60986098
class HashLiteral
6099+
# [LBrace] the left brace that opens this hash
6100+
attr_reader :lbrace
6101+
60996102
# [Array[ AssocNew | AssocSplat ]] the optional contents of the hash
61006103
attr_reader :assocs
61016104

@@ -6105,19 +6108,20 @@ class HashLiteral
61056108
# [Array[ Comment | EmbDoc ]] the comments attached to this node
61066109
attr_reader :comments
61076110

6108-
def initialize(assocs:, location:, comments: [])
6111+
def initialize(lbrace:, assocs:, location:, comments: [])
6112+
@lbrace = lbrace
61096113
@assocs = assocs
61106114
@location = location
61116115
@comments = comments
61126116
end
61136117

61146118
def child_nodes
6115-
assocs
6119+
[lbrace] + assocs
61166120
end
61176121

61186122
def format(q)
61196123
contents = -> do
6120-
q.text("{")
6124+
q.format(lbrace)
61216125
q.indent do
61226126
q.breakable
61236127
q.format(HashFormatter.for(self))
@@ -6156,6 +6160,7 @@ def on_hash(assocs)
61566160
rbrace = find_token(RBrace)
61576161

61586162
HashLiteral.new(
6163+
lbrace: lbrace,
61596164
assocs: assocs || [],
61606165
location: lbrace.location.to(rbrace.location)
61616166
)

0 commit comments

Comments
 (0)