synvert-core 0.29.0 → 0.30.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: 31ee6b89cd48a4accb2dc71fdec2e487c534e8d6eb4a9bd6050817cd88f7ba3c
4
- data.tar.gz: cd4c005e0f7a21e52e984e5279a45d4325d341b92d67feedbbc455ddc062e0fc
3
+ metadata.gz: d60fb908af77ff2aab17f451c37a9f89e2b2af54a5b9aa24b082906286378158
4
+ data.tar.gz: a806d11b423f746ee2004b9467eb976132f1c3053b3986cb0e75e32291730dd6
5
5
  SHA512:
6
- metadata.gz: 4d1e8642e682a155eedb03c6cdbabca55f53f22c258d4774da7200877159ec18c0a7d568823c5c379fd93810d0baf945a2bc139f8444423855c6279241acb0bc
7
- data.tar.gz: 73a369f23d1add90b21ce578faf37a3136a6ffcb384f47fa5b3881fd4241af4b087b19fb0d854143ed1e3d9b76f350fc41b2415cddc29671cde3afe0e46d4709
6
+ metadata.gz: c24af6d0aa4fc55d3a6f35dca86fbcdca5fb66b3e6ba6a8d6e0404da07e0418a2b922ec6d2b4550878c2e422db1befa1f41010c9904eda246753e088bc1c9ea2
7
+ data.tar.gz: c59443f7272ec4b13043fe79bf042b51d8de510143501fcf1d50e1a4fbc6d1d69cba79b007f6854550277bf98d74cef9f71c7aba15a7be6ffa34ea5c275e00da
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.30.0 (2021-04-26)
4
+
5
+ * `goto_node` accepts multiple child node names
6
+ * Match any_value
7
+
3
8
  ## 0.29.0 (2021-04-25)
4
9
 
5
10
  * Make `child_name_range` support [:block, :pipe]
@@ -289,6 +289,8 @@ module Parser::AST
289
289
  key = method_name.to_s.sub('_value', '')
290
290
  return hash_value(key.to_sym)&.to_value if key?(key.to_sym)
291
291
  return hash_value(key.to_s)&.to_value if key?(key.to_s)
292
+
293
+ return nil
292
294
  end
293
295
 
294
296
  super
@@ -465,7 +467,7 @@ module Parser::AST
465
467
  source
466
468
  end
467
469
  end
468
- when String, Symbol
470
+ when String, Symbol, Integer, Float
469
471
  evaluated
470
472
  when NilClass
471
473
  'nil'
@@ -525,6 +527,8 @@ module Parser::AST
525
527
  :false == actual.type
526
528
  when Parser::AST::Node
527
529
  actual == expected
530
+ when Synvert::Core::Rewriter::AnyValue
531
+ !actual.nil?
528
532
  else
529
533
  raise Synvert::Core::MethodNotSupported, "#{expected.class} is not handled for match_value?"
530
534
  end
@@ -44,6 +44,8 @@ module Synvert::Core
44
44
  autoload :RubyVersion, 'synvert/core/rewriter/ruby_version'
45
45
  autoload :GemSpec, 'synvert/core/rewriter/gem_spec'
46
46
 
47
+ autoload :AnyValue, 'synvert/core/rewriter/any_value'
48
+
47
49
  class << self
48
50
  # Execute the temporary rewriter without group and name.
49
51
  #
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Synvert::Core
4
+ class Rewriter::AnyValue
5
+ end
6
+ end
@@ -181,10 +181,10 @@ module Synvert::Core
181
181
  # Parse goto_node dsl, it creates a [Synvert::Core::Rewriter::GotoScope] to go to a child node,
182
182
  # then continue operating on the child node.
183
183
  #
184
- # @param child_node_name [String] the name of the child node.
184
+ # @param *child_node_names [Array] the name of the child nodes.
185
185
  # @param block [Block] block code to continue operating on the matching nodes.
186
- def goto_node(child_node_name, &block)
187
- Rewriter::GotoScope.new(self, child_node_name, &block).process
186
+ def goto_node(*child_node_names, &block)
187
+ Rewriter::GotoScope.new(self, *child_node_names, &block).process
188
188
  end
189
189
 
190
190
  # Parse if_exist_node dsl, it creates a [Synvert::Core::Rewriter::IfExistCondition] to check
@@ -285,6 +285,11 @@ module Synvert::Core
285
285
  @rewriter.add_warning Rewriter::Warning.new(self, message)
286
286
  end
287
287
 
288
+ # Any value but nil.
289
+ def any_value
290
+ Rewriter::AnyValue.new
291
+ end
292
+
288
293
  private
289
294
 
290
295
  # It changes source code from bottom to top, and it can change source code twice at the same time,
@@ -6,11 +6,11 @@ module Synvert::Core
6
6
  # Initialize a scope
7
7
  #
8
8
  # @param instance [Synvert::Core::Rewriter::Instance]
9
- # @param child_node_name [String]
9
+ # @param *child_node_names [Array]
10
10
  # @param block [Block]
11
- def initialize(instance, child_node_name, &block)
11
+ def initialize(instance, *child_node_names, &block)
12
12
  @instance = instance
13
- @child_node_name = child_node_name
13
+ @child_node_names = child_node_names
14
14
  @block = block
15
15
  end
16
16
 
@@ -19,7 +19,10 @@ module Synvert::Core
19
19
  current_node = @instance.current_node
20
20
  return unless current_node
21
21
 
22
- child_node = @child_node_name.is_a?(Parser::AST::Node) ? @child_node_name : current_node.send(@child_node_name)
22
+ child_node = current_node
23
+ @child_node_names.each do |child_node_name|
24
+ child_node = child_node_name.is_a?(Parser::AST::Node) ? child_node_name : child_node.send(child_node_name)
25
+ end
23
26
  @instance.process_with_other_node child_node do
24
27
  @instance.instance_eval(&@block)
25
28
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Synvert
4
4
  module Core
5
- VERSION = '0.29.0'
5
+ VERSION = '0.30.0'
6
6
  end
7
7
  end
@@ -335,11 +335,13 @@ describe Parser::AST::Node do
335
335
 
336
336
  describe 'key value by method_missing' do
337
337
  it 'gets for key value' do
338
- node = parse("{:foo => :bar}")
338
+ node = parse('{:foo => :bar}')
339
339
  expect(node.foo_value).to eq :bar
340
340
 
341
341
  node = parse("{'foo' => 'bar'}")
342
342
  expect(node.foo_value).to eq 'bar'
343
+
344
+ expect(node.bar_value).to be_nil
343
345
  end
344
346
  end
345
347
 
@@ -54,9 +54,9 @@ module Synvert::Core
54
54
  it 'parses goto_node' do
55
55
  scope = double
56
56
  block = proc {}
57
- expect(Rewriter::GotoScope).to receive(:new).with(instance, :caller, &block).and_return(scope)
57
+ expect(Rewriter::GotoScope).to receive(:new).with(instance, :caller, :receiver, &block).and_return(scope)
58
58
  expect(scope).to receive(:process)
59
- instance.goto_node(:caller, &block)
59
+ instance.goto_node(:caller, :receiver, &block)
60
60
  end
61
61
 
62
62
  it 'parses if_exist_node' do
@@ -8,12 +8,11 @@ module Synvert::Core
8
8
  rewriter = Rewriter.new('foo', 'bar')
9
9
  Rewriter::Instance.new(rewriter, 'file pattern')
10
10
  }
11
- let(:source) {
12
- '
13
- Factory.define :user do |user|
14
- end
15
- '
16
- }
11
+ let(:source) { <<~EOS }
12
+ Factory.define :user do |user|
13
+ end
14
+ EOS
15
+
17
16
  let(:node) { Parser::CurrentRuby.parse(source) }
18
17
  before do
19
18
  Rewriter::Instance.reset
@@ -25,13 +24,13 @@ end
25
24
  run = false
26
25
  type_in_scope = nil
27
26
  scope =
28
- Rewriter::GotoScope.new instance, :caller do
27
+ Rewriter::GotoScope.new instance, :caller, :receiver do
29
28
  run = true
30
29
  type_in_scope = node.type
31
30
  end
32
31
  scope.process
33
32
  expect(run).to be_truthy
34
- expect(type_in_scope).to eq :send
33
+ expect(type_in_scope).to eq :const
35
34
  expect(instance.current_node.type).to eq :block
36
35
  end
37
36
  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.29.0
4
+ version: 0.30.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-04-25 00:00:00.000000000 Z
11
+ date: 2021-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -154,6 +154,7 @@ files:
154
154
  - lib/synvert/core/rewriter/action/replace_action.rb
155
155
  - lib/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action.rb
156
156
  - lib/synvert/core/rewriter/action/replace_with_action.rb
157
+ - lib/synvert/core/rewriter/any_value.rb
157
158
  - lib/synvert/core/rewriter/condition.rb
158
159
  - lib/synvert/core/rewriter/condition/if_exist_condition.rb
159
160
  - lib/synvert/core/rewriter/condition/if_only_exist_condition.rb