synvert-core 0.46.0 → 0.47.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/synvert/core/node_ext.rb +30 -0
- data/lib/synvert/core/version.rb +1 -1
- data/spec/synvert/core/node_ext_spec.rb +55 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c9673a5aa5ad59322786e09e99a527e7f7a7e05c7067200c9baed0602c7c1fe2
|
|
4
|
+
data.tar.gz: e946fa740f8678faa4f1cb856c2d6a54b4b0c09ed10084110bb78648da1a7497
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cebcaad6d3a1162b0ceb8354ae2d598f18e70474e068b8a91cdea8440c83f02280afae97adb8c923a5dbe7750138f02e5b73a633f4b7dbd9dfa9b0c90962c14a
|
|
7
|
+
data.tar.gz: b482a97216175c0a16492bdb23294acc33727493202c088d44a94fb73f15df6263d1addf2df5e2ef53cecc7147ff475e67c12e2eb9f3451b6c92b4b47eee42d4
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## 0.47.0 (2021-07-28)
|
|
4
|
+
|
|
5
|
+
* Add `to_single_quote` to `str` node
|
|
6
|
+
* Add `to_symbol` to `str` node
|
|
7
|
+
* Add `to_lambda_literal` to `lambda` node
|
|
8
|
+
|
|
3
9
|
## 0.46.0 (2021-07-25)
|
|
4
10
|
|
|
5
11
|
* Add `strip_curly_braces` and `wrap_curly_braces` for `hash` node
|
|
@@ -504,6 +504,36 @@ module Parser::AST
|
|
|
504
504
|
"{ #{to_source} }"
|
|
505
505
|
end
|
|
506
506
|
|
|
507
|
+
# get single quote string
|
|
508
|
+
def to_single_quote
|
|
509
|
+
return to_source unless type == :str
|
|
510
|
+
|
|
511
|
+
"'#{to_value}'"
|
|
512
|
+
end
|
|
513
|
+
|
|
514
|
+
# convert string to symbol
|
|
515
|
+
def to_symbol
|
|
516
|
+
return to_source unless type == :str
|
|
517
|
+
|
|
518
|
+
":#{to_value}"
|
|
519
|
+
end
|
|
520
|
+
|
|
521
|
+
# convert lambda {} to -> {}
|
|
522
|
+
def to_lambda_literal
|
|
523
|
+
if type == :block && caller.type == :send && caller.receiver.nil? && caller.message == :lambda
|
|
524
|
+
new_source = to_source
|
|
525
|
+
if arguments.size > 1
|
|
526
|
+
new_source = new_source[0...arguments.loc.begin.to_range.begin - 1] + new_source[arguments.loc.end.to_range.end..-1]
|
|
527
|
+
new_source = new_source.sub('lambda', "->(#{arguments.map(&:to_source).join(', ')})")
|
|
528
|
+
else
|
|
529
|
+
new_source = new_source.sub('lambda', '->')
|
|
530
|
+
end
|
|
531
|
+
new_source
|
|
532
|
+
else
|
|
533
|
+
to_source
|
|
534
|
+
end
|
|
535
|
+
end
|
|
536
|
+
|
|
507
537
|
private
|
|
508
538
|
|
|
509
539
|
# Compare actual value with expected value.
|
data/lib/synvert/core/version.rb
CHANGED
|
@@ -706,10 +706,64 @@ describe Parser::AST::Node do
|
|
|
706
706
|
end
|
|
707
707
|
|
|
708
708
|
context 'other node' do
|
|
709
|
-
it '
|
|
709
|
+
it 'does nothing' do
|
|
710
710
|
node = parse("'foobar'")
|
|
711
711
|
expect(node.wrap_curly_braces).to eq("'foobar'")
|
|
712
712
|
end
|
|
713
713
|
end
|
|
714
714
|
end
|
|
715
|
+
|
|
716
|
+
describe '#to_single_quote' do
|
|
717
|
+
context 'str node' do
|
|
718
|
+
it 'converts double quote to single quote' do
|
|
719
|
+
node = parse('"foobar"')
|
|
720
|
+
expect(node.to_source).to eq '"foobar"'
|
|
721
|
+
expect(node.to_single_quote).to eq "'foobar'"
|
|
722
|
+
end
|
|
723
|
+
end
|
|
724
|
+
|
|
725
|
+
context 'other node' do
|
|
726
|
+
it 'does nothing' do
|
|
727
|
+
node = parse(':foobar')
|
|
728
|
+
expect(node.to_single_quote).to eq ':foobar'
|
|
729
|
+
end
|
|
730
|
+
end
|
|
731
|
+
end
|
|
732
|
+
|
|
733
|
+
describe '#to_symbol' do
|
|
734
|
+
context 'str node' do
|
|
735
|
+
it 'converts string to symbol' do
|
|
736
|
+
node = parse("'foobar'")
|
|
737
|
+
expect(node.to_symbol).to eq ':foobar'
|
|
738
|
+
end
|
|
739
|
+
end
|
|
740
|
+
|
|
741
|
+
context 'other node' do
|
|
742
|
+
it 'does nothing' do
|
|
743
|
+
node = parse(':foobar')
|
|
744
|
+
expect(node.to_symbol).to eq ':foobar'
|
|
745
|
+
end
|
|
746
|
+
end
|
|
747
|
+
end
|
|
748
|
+
|
|
749
|
+
describe '#to_lambda_literal' do
|
|
750
|
+
context 'lambda node' do
|
|
751
|
+
it 'converts to lambda literal without arguments' do
|
|
752
|
+
node = parse('lambda { foobar }')
|
|
753
|
+
expect(node.to_lambda_literal).to eq('-> { foobar }')
|
|
754
|
+
end
|
|
755
|
+
|
|
756
|
+
it 'converts to lambda literal with arguments' do
|
|
757
|
+
node = parse('lambda { |x, y| foobar }')
|
|
758
|
+
expect(node.to_lambda_literal).to eq('->(x, y) { foobar }')
|
|
759
|
+
end
|
|
760
|
+
end
|
|
761
|
+
|
|
762
|
+
context 'other node' do
|
|
763
|
+
it 'does nothing' do
|
|
764
|
+
node = parse(':foobar')
|
|
765
|
+
expect(node.to_lambda_literal).to eq ':foobar'
|
|
766
|
+
end
|
|
767
|
+
end
|
|
768
|
+
end
|
|
715
769
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: synvert-core
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.47.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Richard Huang
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-07-
|
|
11
|
+
date: 2021-07-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|