Skip to content

Commit 53a27bf

Browse files
authored
Merge pull request #77 from ruby-syntax-tree/label
Correct the pattern for checking if a dynamic symbol can be converted into a label as a hash key.
2 parents 34a4782 + a69e958 commit 53a27bf

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
66

77
## [Unreleased]
88

9+
### Changed
10+
11+
- Correct the pattern for checking if a dynamic symbol can be converted into a label as a hash key.
12+
913
## [2.4.1] - 2022-05-10
1014

1115
- [#73](https://github.com/ruby-syntax-tree/syntax_tree/pull/73) - Fix nested hash patterns from accidentally adding a `then` to their output.

lib/syntax_tree/node.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,7 @@ def format(q)
13881388
module HashKeyFormatter
13891389
# Formats the keys of a hash literal using labels.
13901390
class Labels
1391-
LABEL = /^[@$_A-Za-z]([_A-Za-z0-9]*)?([!_=?A-Za-z0-9])?$/
1391+
LABEL = /\A[A-Za-z_](\w*[\w!?])?\z/
13921392

13931393
def format_key(q, key)
13941394
case key

test/fixtures/assoc.rb

+2
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,5 @@
4646
{ foo: "bar" }
4747
%
4848
{ "foo #{bar}": "baz" }
49+
%
50+
{ "foo=": "baz" }

0 commit comments

Comments
 (0)