synvert-core 0.52.0 → 0.52.1

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: 346c7567c1fec413a81afbe2ec5348f9cd66ac03ed08e8a6cf0fbf47ba049d08
4
- data.tar.gz: c4a274d516c1301eb0be17777bd26a16561943077260508925cc3c5eae43e799
3
+ metadata.gz: b0ab6b6fbee0d7b58203ccde9af31179caa3f6cd0b52bdceb8262683daa31e1e
4
+ data.tar.gz: 0670bf038c8e7074893e68eafc4a60e4a27c94d4287dda21a7ab6a03322ce044
5
5
  SHA512:
6
- metadata.gz: ee568051d2872db9f81c7d9a3609379eba74db82862ad55976b962e0c4b835dca9f7af74c67014554f6ee919edde2dab050a77fc248bc71ed2c4969009cede1d
7
- data.tar.gz: 80dd4085d700581a02dd9507e88e0cbf28e978cbbd61d0e0906c73d2f713abbdd9393caec13d6854b3727d1b1fdd87a673d67323b4b315990a00f06fa23a1f44
6
+ metadata.gz: ceae8c9049ae4488f4831594ba2527c970ba88a8479d0eb1477e832597de59f7ca2e9e45389eab4bfa609f8eb2de9498d54340163323cc1329278ad90de1db70
7
+ data.tar.gz: 5a74ad849852d919bc274726201a03f00aec7741ddd8a8a3abd4a38e3f1584a358a7ca65c2238d885686274d1cfe9157dd4b5b74ac971bb05efd0af411366ae0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.52.1 (2021-08-21)
4
+
5
+ * Fix nested child in Node#child_node_range
6
+
3
7
  ## 0.52.0 (2021-08-21)
4
8
 
5
9
  * ``Node#child_node_range`` supports nested child
@@ -341,7 +341,7 @@ module Parser::AST
341
341
  # @param [String] name of child node.
342
342
  # @return [Parser::Source::Range] source range of child node.
343
343
  def child_node_range(child_name)
344
- case [type, child_name]
344
+ case [type, child_name.to_sym]
345
345
  when %i[block pipes], %i[def parentheses], %i[defs parentheses]
346
346
  Parser::Source::Range.new('(string)', arguments.loc.expression.begin_pos, arguments.loc.expression.end_pos)
347
347
  when %i[block arguments], %i[def arguments], %i[defs arguments]
@@ -369,35 +369,38 @@ module Parser::AST
369
369
  Parser::Source::Range.new('(string)', loc.begin.begin_pos, loc.end.end_pos)
370
370
  end
371
371
  else
372
- child_node = self
373
- child_name.to_s.split('.').each do |key|
374
- if child_node.respond_to?(key)
375
- child_node = child_node.send(key)
376
- return nil if child_node.nil?
377
- else
378
- raise Synvert::Core::MethodNotSupported,
379
- "child_node_range is not handled for #{child_node.debug_info}, child_name: #{child_name}"
372
+ direct_child_name, nested_child_name = child_name.to_s.split('.', 2)
373
+ if respond_to?(direct_child_name)
374
+ child_node = send(direct_child_name)
375
+
376
+ return child_node.child_node_range(nested_child_name) if nested_child_name
377
+
378
+ return nil if child_node.nil?
379
+
380
+ if child_node.is_a?(Parser::AST::Node)
381
+ return(
382
+ Parser::Source::Range.new(
383
+ '(string)',
384
+ child_node.loc.expression.begin_pos,
385
+ child_node.loc.expression.end_pos
386
+ )
387
+ )
380
388
  end
381
- end
382
389
 
383
- if child_node.is_a?(Parser::AST::Node)
390
+ # arguments
391
+ return nil if child_node.empty?
392
+
384
393
  return(
385
394
  Parser::Source::Range.new(
386
395
  '(string)',
387
- child_node.loc.expression.begin_pos,
388
- child_node.loc.expression.end_pos
396
+ child_node.first.loc.expression.begin_pos,
397
+ child_node.last.loc.expression.end_pos
389
398
  )
390
399
  )
391
400
  end
392
401
 
393
- # arguments
394
- return nil if child_node.empty?
395
-
396
- Parser::Source::Range.new(
397
- '(string)',
398
- child_node.first.loc.expression.begin_pos,
399
- child_node.last.loc.expression.end_pos
400
- )
402
+ raise Synvert::Core::MethodNotSupported,
403
+ "child_node_range is not handled for #{debug_info}, child_name: #{child_name}"
401
404
  end
402
405
  end
403
406
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Synvert
4
4
  module Core
5
- VERSION = '0.52.0'
5
+ VERSION = '0.52.1'
6
6
  end
7
7
  end
@@ -526,6 +526,12 @@ describe Parser::AST::Node do
526
526
  range = node.child_node_range('caller.receiver')
527
527
  expect(range.to_range).to eq(0...7)
528
528
  end
529
+
530
+ it 'checks caller.message' do
531
+ node = parse('Factory.define :user do |user|; end')
532
+ range = node.child_node_range('caller.message')
533
+ expect(range.to_range).to eq(8...14)
534
+ end
529
535
  end
530
536
 
531
537
  context 'class node' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: synvert-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.52.0
4
+ version: 0.52.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang