File tree 6 files changed +26
-7
lines changed
6 files changed +26
-7
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
6
6
7
7
## [ Unreleased]
8
8
9
+ ## [ 2.4.1] - 2022-05-10
10
+
11
+ - Fix nested hash patterns from accidentally adding a ` then ` to their output.
12
+
9
13
## [ 2.4.0] - 2022-05-07
10
14
11
15
### Added
@@ -209,7 +213,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
209
213
210
214
- 🎉 Initial release! 🎉
211
215
212
- [ unreleased ] : https://github.com/ruby-syntax-tree/syntax_tree/compare/v2.4.0...HEAD
216
+ [ unreleased ] : https://github.com/ruby-syntax-tree/syntax_tree/compare/v2.4.1...HEAD
217
+ [ 2.4.1 ] : https://github.com/ruby-syntax-tree/syntax_tree/compare/v2.4.0...v2.4.1
213
218
[ 2.4.0 ] : https://github.com/ruby-syntax-tree/syntax_tree/compare/v2.3.1...v2.4.0
214
219
[ 2.3.1 ] : https://github.com/ruby-syntax-tree/syntax_tree/compare/v2.3.0...v2.3.1
215
220
[ 2.3.0 ] : https://github.com/ruby-syntax-tree/syntax_tree/compare/v2.2.0...v2.3.0
Original file line number Diff line number Diff line change 1
1
PATH
2
2
remote: .
3
3
specs:
4
- syntax_tree (2.4.0 )
4
+ syntax_tree (2.4.1 )
5
5
6
6
GEM
7
7
remote: https://rubygems.org/
Original file line number Diff line number Diff line change @@ -5064,13 +5064,16 @@ def format(q)
5064
5064
parts = keywords . map { |( key , value ) | KeywordFormatter . new ( key , value ) }
5065
5065
parts << KeywordRestFormatter . new ( keyword_rest ) if keyword_rest
5066
5066
5067
+ nested = PATTERNS . include? ( q . parent . class )
5067
5068
contents = -> do
5068
5069
q . group { q . seplist ( parts ) { |part | q . format ( part , stackable : false ) } }
5069
5070
5070
5071
# If there isn't a constant, and there's a blank keyword_rest, then we
5071
5072
# have an plain ** that needs to have a `then` after it in order to
5072
5073
# parse correctly on the next parse.
5073
- q . text ( " then" ) if !constant && keyword_rest && keyword_rest . value . nil?
5074
+ if !constant && keyword_rest && keyword_rest . value . nil? && !nested
5075
+ q . text ( " then" )
5076
+ end
5074
5077
end
5075
5078
5076
5079
# If there is a constant, we're going to format to have the constant name
@@ -5097,7 +5100,7 @@ def format(q)
5097
5100
5098
5101
# If there's only one pair, then we'll just print the contents provided
5099
5102
# we're not inside another pattern.
5100
- if !PATTERNS . include? ( q . parent . class ) && parts . size == 1
5103
+ if !nested && parts . size == 1
5101
5104
contents . call
5102
5105
return
5103
5106
end
Original file line number Diff line number Diff line change @@ -1671,9 +1671,15 @@ def on_heredoc_end(value)
1671
1671
# (nil | VarField) keyword_rest
1672
1672
# ) -> HshPtn
1673
1673
def on_hshptn ( constant , keywords , keyword_rest )
1674
- # Create an artificial VarField if we find an extra ** on the end
1675
- if !keyword_rest && ( token = find_token ( Op , "**" , consume : false ) )
1674
+ if keyword_rest
1675
+ # We're doing this to delete the token from the list so that it doesn't
1676
+ # confuse future patterns by thinking they have an extra ** on the end.
1677
+ find_token ( Op , "**" )
1678
+ elsif ( token = find_token ( Op , "**" , consume : false ) )
1676
1679
tokens . delete ( token )
1680
+
1681
+ # Create an artificial VarField if we find an extra ** on the end. This
1682
+ # means the formatting will be a little more consistent.
1677
1683
keyword_rest = VarField . new ( value : nil , location : token . location )
1678
1684
end
1679
1685
Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
3
module SyntaxTree
4
- VERSION = "2.4.0 "
4
+ VERSION = "2.4.1 "
5
5
end
Original file line number Diff line number Diff line change 66
66
case foo
67
67
in **nil
68
68
end
69
+ %
70
+ case foo
71
+ in bar, { baz:, **nil }
72
+ in qux:
73
+ end
You can’t perform that action at this time.
0 commit comments