synvert-core 0.61.2 → 0.62.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7f5de89db1e920d9a0f1f55543f5e68121daaadec9c28558438561a303e1ef52
4
- data.tar.gz: b7b491df1978ab9a628b4230753332044b1fe6d4fd53426b80d4047c3da9fbf7
3
+ metadata.gz: 4e6217815771ca45d3fc81030b42ae126252ab800e127518e72c2f2b4dd2eb5c
4
+ data.tar.gz: 266cc5cda364f6df8100a290d393f879075b433acfd7ee70c780b37d23a83292
5
5
  SHA512:
6
- metadata.gz: 0b5957ba9a2812b7efeb224d0aa8776cdde9c664f35a35b1247e2445fe294c2c803c83eb4d6b4c7be4bde98ea0a196982ac7ae8974fc3c90874bf396b15d7d1c
7
- data.tar.gz: e8d838167caff111711f4fc61cb431b52eb53817a268f65c920f915e31c6a0fb785f1bbaa43f43210657b2c93db7d33656f4c9338e887d5f0afdc1a004eb7167
6
+ metadata.gz: 89c3f93da22298305839c57fadb4963ea0973e16de10b2d2260c76e63927d25c302bbcd2c74515e79adeb24d2440ecba53025aaeeab0b173c6176adccb5d0875
7
+ data.tar.gz: df7a75da7a8bbecee35d4cc1afb862f6aa0184e96d484a6f207a88510dfac70098ea17cca794aefaac0938e37e96d8a91f7ba21738f2f116554238f02344e4c1
data/CHANGELOG.md CHANGED
@@ -1,13 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
- ## 0.61.2 (2021-12-21)
3
+ ## 0.62.0 (2021-12-24)
4
4
 
5
- * Restrict activesupport version to ~> 6
6
-
7
- ## 0.61.1 (2021-12-12)
8
-
9
- * Fix prepend action for def and defs nodes
10
- * Fix append action for def and defs nodes
5
+ * Support `csend` node
6
+ * Restrict `activesupport` version to `~> 6`
7
+ * Fix `prepend` action for `def` and `defs` nodes
8
+ * Fix `append` action for `def` and `defs` nodes
11
9
 
12
10
  ## 0.61.0 (2021-12-10)
13
11
 
@@ -49,7 +49,7 @@ module Parser::AST
49
49
  # @return [Parser::AST::Node] receiver node.
50
50
  # @raise [Synvert::Core::MethodNotSupported] if calls on other node.
51
51
  def receiver
52
- if :send == type
52
+ if %i[csend send].include?(type)
53
53
  children[0]
54
54
  else
55
55
  raise Synvert::Core::MethodNotSupported, "receiver is not handled for #{debug_info}"
@@ -64,7 +64,7 @@ module Parser::AST
64
64
  case type
65
65
  when :super, :zsuper
66
66
  :super
67
- when :send
67
+ when :send, :csend
68
68
  children[1]
69
69
  else
70
70
  raise Synvert::Core::MethodNotSupported, "message is not handled for #{debug_info}"
@@ -81,7 +81,7 @@ module Parser::AST
81
81
  children[1]
82
82
  when :defs
83
83
  children[2]
84
- when :send
84
+ when :send, :csend
85
85
  children[2..-1]
86
86
  when :defined?
87
87
  children
@@ -400,15 +400,15 @@ module Parser::AST
400
400
  loc.operator
401
401
  when %i[defs self]
402
402
  Parser::Source::Range.new('(string)', loc.operator.begin_pos - 'self'.length, loc.operator.begin_pos)
403
- when %i[send dot]
403
+ when %i[send dot], %i[csend dot]
404
404
  loc.dot
405
- when %i[send message]
405
+ when %i[send message], %i[csend message]
406
406
  if loc.operator
407
407
  Parser::Source::Range.new('(string)', loc.selector.begin_pos, loc.operator.end_pos)
408
408
  else
409
409
  loc.selector
410
410
  end
411
- when %i[send parentheses]
411
+ when %i[send parentheses], %i[csend parentheses]
412
412
  if loc.begin && loc.end
413
413
  Parser::Source::Range.new('(string)', loc.begin.begin_pos, loc.end.end_pos)
414
414
  end
@@ -593,7 +593,7 @@ module Parser::AST
593
593
  def to_string
594
594
  return to_source unless type == :sym
595
595
 
596
- "#{to_value}"
596
+ to_value.to_s
597
597
  end
598
598
 
599
599
  # convert lambda {} to -> {}
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Synvert
4
4
  module Core
5
- VERSION = '0.61.2'
5
+ VERSION = '0.62.0'
6
6
  end
7
7
  end
@@ -80,6 +80,11 @@ describe Parser::AST::Node do
80
80
  node = parse('FactoryGirl.create :post')
81
81
  expect(node.receiver).to eq parse('FactoryGirl')
82
82
  end
83
+
84
+ it 'gets for csend node' do
85
+ node = parse('user&.update(name: name)')
86
+ expect(node.receiver).to eq parse('user')
87
+ end
83
88
  end
84
89
 
85
90
  describe '#message' do
@@ -88,6 +93,11 @@ describe Parser::AST::Node do
88
93
  expect(node.message).to eq :create
89
94
  end
90
95
 
96
+ it 'gets for csend node' do
97
+ node = parse('user&.update(name: name)')
98
+ expect(node.message).to eq :update
99
+ end
100
+
91
101
  it 'gets for super node' do
92
102
  node = parse('super(params)')
93
103
  expect(node.message).to eq :super
@@ -137,6 +147,11 @@ describe Parser::AST::Node do
137
147
  expect(node.arguments).to eq parse("[:post, title: 'post']").children
138
148
  end
139
149
 
150
+ it 'gets for csend node' do
151
+ node = parse('user&.update(name: name)')
152
+ expect(node.arguments).to eq parse('[name: name]').children
153
+ end
154
+
140
155
  it 'gets for defined? node' do
141
156
  node = parse('defined?(Bundler)')
142
157
  expect(node.arguments).to eq [parse('Bundler')]
@@ -653,6 +668,50 @@ describe Parser::AST::Node do
653
668
  end
654
669
  end
655
670
 
671
+ context 'csend node' do
672
+ it 'checks receiver' do
673
+ node = parse('foo&.bar(test)')
674
+ range = node.child_node_range(:receiver)
675
+ expect(range.to_range).to eq(0...3)
676
+ end
677
+
678
+ it 'checks dot' do
679
+ node = parse('foo&.bar(test)')
680
+ range = node.child_node_range(:dot)
681
+ expect(range.to_range).to eq(3...5)
682
+ end
683
+
684
+ it 'checks message' do
685
+ node = parse('foo&.bar(test)')
686
+ range = node.child_node_range(:message)
687
+ expect(range.to_range).to eq(5...8)
688
+
689
+ node = parse('foo&.bar = test')
690
+ range = node.child_node_range(:message)
691
+ expect(range.to_range).to eq(5...10)
692
+ end
693
+
694
+ it 'checks arguments' do
695
+ node = parse('foo&.bar(test)')
696
+ range = node.child_node_range(:arguments)
697
+ expect(range.to_range).to eq(9...13)
698
+
699
+ node = parse('foo&.bar')
700
+ range = node.child_node_range(:arguments)
701
+ expect(range).to be_nil
702
+ end
703
+
704
+ it 'checks parentheses' do
705
+ node = parse('foo&.bar(test)')
706
+ range = node.child_node_range(:parentheses)
707
+ expect(range.to_range).to eq(8...14)
708
+
709
+ node = parse('foo&.bar')
710
+ range = node.child_node_range(:parentheses)
711
+ expect(range).to be_nil
712
+ end
713
+ end
714
+
656
715
  context 'def node' do
657
716
  it 'checks name' do
658
717
  node = parse('def foo(bar); 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.61.2
4
+ version: 0.62.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-12-21 00:00:00.000000000 Z
11
+ date: 2021-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -218,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
218
218
  - !ruby/object:Gem::Version
219
219
  version: '0'
220
220
  requirements: []
221
- rubygems_version: 3.2.32
221
+ rubygems_version: 3.2.22
222
222
  signing_key:
223
223
  specification_version: 4
224
224
  summary: convert ruby code to better syntax.