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

Commit be97d5b

Browse files
committed
Allow arrays of CHAR nodes to be converted to QWords under certain conditions.
1 parent 3163315 commit be97d5b

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
1111
- The ability to "check" formatting by formatting the output of the first format.
1212
- Comments can now be attached to the `case` keyword.
1313
- Remove escaped forward slashes from regular expression literals when converting to `%r`.
14+
- Allow arrays of `CHAR` nodes to be converted to `QWords` under certain conditions.
1415

1516
### Changed
1617

lib/syntax_tree.rb

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,7 +1355,11 @@ def format(q)
13551355
q.indent do
13561356
q.breakable("")
13571357
q.seplist(contents.parts, -> { q.breakable }) do |part|
1358-
q.format(part.parts.first)
1358+
if part.is_a?(StringLiteral)
1359+
q.format(part.parts.first)
1360+
else
1361+
q.text(part.value[1..-1])
1362+
end
13591363
end
13601364
end
13611365
q.breakable("")
@@ -1450,10 +1454,17 @@ def to_json(*opts)
14501454
def qwords?
14511455
contents && contents.comments.empty? && contents.parts.length > 1 &&
14521456
contents.parts.all? do |part|
1453-
part.is_a?(StringLiteral) && part.comments.empty? &&
1454-
part.parts.length == 1 &&
1455-
part.parts.first.is_a?(TStringContent) &&
1456-
!part.parts.first.value.match?(/[\s\[\]\\]/)
1457+
case part
1458+
when StringLiteral
1459+
part.comments.empty? &&
1460+
part.parts.length == 1 &&
1461+
part.parts.first.is_a?(TStringContent) &&
1462+
!part.parts.first.value.match?(/[\s\[\]\\]/)
1463+
when CHAR
1464+
!part.value.match?(/[\[\]\\]/)
1465+
else
1466+
false
1467+
end
14571468
end
14581469
end
14591470

0 commit comments

Comments
 (0)