node_mutation 1.4.3 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 739b5f521fb0df8ea2e4b47f11851574e4e771528923fa89e0d7c5a2ed8a0b7b
4
- data.tar.gz: fe8c44a82ef5a21df6390936f7b5b91700c8a7f965e34ada1229ef2443b013c6
3
+ metadata.gz: b66c8223045972f4f91cdae0b61a5589c04e7f53f3eedf66b1c0eebee9d66b1c
4
+ data.tar.gz: 64a47a10bce6886a876cd04b08ff37118e6094bcc40d1e909e861d6f25c37d43
5
5
  SHA512:
6
- metadata.gz: b2dd045bc579535b9ba6c6ece53c8f19ae840385682ca0f3759713b5ee36abca574cbf4a80c065b024ecbf40d23a39c423b6e7ecd3a82d4417f7b65583b78885
7
- data.tar.gz: 298af0ed4518668a784df4e5c3fec4a3904fa63fc325ace94d90ec869cd111efe5e20829b6f0f8902264f38fe87ea2359c65db1ada2170813b4ce62886fdbaef
6
+ metadata.gz: 12f5cd0bc631511de6d7b250dec14869ce1e19d5c311ac59e5722578f2fa15f51b17be600d5fc59a3ef5ffaa1607e209ccc6e611e2046f1a9005cffb693367a9
7
+ data.tar.gz: 7d3496c675ed29a8ddaa35d3fbf4b538677a44016696c40020e518afa62526fa5e7ad2abec2b7339732adabb820fa037795c3d8597b0149a2cd0502c23c95883
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # NodeMutation
2
2
 
3
+ ## 1.5.0 (2022-10-17)
4
+
5
+ * Remove `insert_after`
6
+ * Fix regexp to match evaluated value
7
+
8
+ ## 1.4.4 (2022-09-26)
9
+
10
+ * Parser adapter `child_node_by_name` support function call
11
+
3
12
  ## 1.4.3 (2022-09-24)
4
13
 
5
14
  * Update source only if `new_code` is not `nil`
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- node_mutation (1.4.3)
4
+ node_mutation (1.5.0)
5
5
  activesupport (< 7.0.0)
6
6
  erubis
7
7
 
@@ -75,7 +75,7 @@ GEM
75
75
  thor (1.2.1)
76
76
  tzinfo (2.0.5)
77
77
  concurrent-ruby (~> 1.0)
78
- zeitwerk (2.6.0)
78
+ zeitwerk (2.6.1)
79
79
 
80
80
  PLATFORMS
81
81
  x86_64-darwin-21
data/README.md CHANGED
@@ -37,8 +37,6 @@ mutation.append node, 'include FactoryGirl::Syntax::Methods'
37
37
  mutation.delete node, :dot, :message, and_comma: true
38
38
  # insert code to the ast node.
39
39
  mutation.insert node, 'URI.', at: 'beginning'
40
- # insert code next to the ast node.
41
- mutation.insert_after node, '{{arguments.first}}.include FactoryGirl::Syntax::Methods'
42
40
  # prepend code to the ast node.
43
41
  mutation.prepend node, '{{arguments.first}}.include FactoryGirl::Syntax::Methods'
44
42
  # remove source code of the ast node
@@ -6,7 +6,7 @@ class NodeMutation::ParserAdapter < NodeMutation::Adapter
6
6
  end
7
7
 
8
8
  def rewritten_source(node, code)
9
- code.gsub(/{{(.*?)}}/m) do
9
+ code.gsub(/{{(.+?)}}/m) do
10
10
  old_code = Regexp.last_match(1)
11
11
  if node.respond_to?(old_code.split('.').first)
12
12
  evaluated = child_node_by_name(node, old_code)
@@ -161,14 +161,18 @@ class NodeMutation::ParserAdapter < NodeMutation::Adapter
161
161
 
162
162
  if node.respond_to?(direct_child_name)
163
163
  child_node = node.send(direct_child_name)
164
+ elsif direct_child_name.include?('(') && direct_child_name.include?(')')
165
+ child_node = eval("node.#{direct_child_name}")
166
+ else
167
+ child_node = nil
168
+ end
164
169
 
165
- return child_node_by_name(child_node, nested_child_name) if nested_child_name
170
+ return child_node_by_name(child_node, nested_child_name) if nested_child_name
166
171
 
167
- return nil if child_node.nil?
172
+ return nil if child_node.nil?
168
173
 
169
- return child_node if child_node.is_a?(Parser::AST::Node)
174
+ return child_node if child_node.is_a?(Parser::AST::Node)
170
175
 
171
- return child_node
172
- end
176
+ return child_node
173
177
  end
174
178
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class NodeMutation
4
- VERSION = "1.4.3"
4
+ VERSION = "1.5.0"
5
5
  end
data/lib/node_mutation.rb CHANGED
@@ -18,7 +18,6 @@ class NodeMutation
18
18
  autoload :AppendAction, 'node_mutation/action/append_action'
19
19
  autoload :DeleteAction, 'node_mutation/action/delete_action'
20
20
  autoload :InsertAction, 'node_mutation/action/insert_action'
21
- autoload :InsertAfterAction, 'node_mutation/action/insert_after_action'
22
21
  autoload :RemoveAction, 'node_mutation/action/remove_action'
23
22
  autoload :PrependAction, 'node_mutation/action/prepend_action'
24
23
  autoload :ReplaceAction, 'node_mutation/action/replace_action'
@@ -112,21 +111,6 @@ class NodeMutation
112
111
  @actions << InsertAction.new(node, code, at: at, to: to).process
113
112
  end
114
113
 
115
- # Insert code next to the ast node.
116
- # @param node [Node] ast node
117
- # @param code [String] new code to insert.
118
- # @example
119
- # source code of the ast node is
120
- # Synvert::Application.config.secret_token = "0447aa931d42918bfb934750bb78257088fb671186b5d1b6f9fddf126fc8a14d34f1d045cefab3900751c3da121a8dd929aec9bafe975f1cabb48232b4002e4e"
121
- # then we call
122
- # mutation.insert_after(node, "{{receiver}}.secret_key_base = \"#{SecureRandom.hex(64)}\"")
123
- # the source code will be rewritten to
124
- # Synvert::Application.config.secret_token = "0447aa931d42918bfb934750bb78257088fb671186b5d1b6f9fddf126fc8a14d34f1d045cefab3900751c3da121a8dd929aec9bafe975f1cabb48232b4002e4e"
125
- # Synvert::Application.config.secret_key_base = "bf4f3f46924ecd9adcb6515681c78144545bba454420973a274d7021ff946b8ef043a95ca1a15a9d1b75f9fbdf85d1a3afaf22f4e3c2f3f78e24a0a188b581df"
126
- def insert_after(node, code)
127
- @actions << InsertAfterAction.new(node, code).process
128
- end
129
-
130
114
  # Prepend code to the ast node.
131
115
  # @param node [Node] ast node
132
116
  # @param code [String] new code to prepend.
@@ -27,8 +27,6 @@ module NodeMutation[T]
27
27
 
28
28
  def insert: (node: T, code: String, ?at: "beginning" | "end", ?to: nil | String) -> void
29
29
 
30
- def insert_after: (node: T, code: String) -> void
31
-
32
30
  def prepend: (node: T, code: String) -> void
33
31
 
34
32
  def remove: (node: T, **options: { and_comma: bool }) -> void
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: node_mutation
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.3
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-23 00:00:00.000000000 Z
11
+ date: 2022-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -58,7 +58,6 @@ files:
58
58
  - lib/node_mutation/action/append_action.rb
59
59
  - lib/node_mutation/action/delete_action.rb
60
60
  - lib/node_mutation/action/insert_action.rb
61
- - lib/node_mutation/action/insert_after_action.rb
62
61
  - lib/node_mutation/action/noop_action.rb
63
62
  - lib/node_mutation/action/prepend_action.rb
64
63
  - lib/node_mutation/action/remove_action.rb
@@ -96,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
95
  - !ruby/object:Gem::Version
97
96
  version: '0'
98
97
  requirements: []
99
- rubygems_version: 3.3.7
98
+ rubygems_version: 3.3.22
100
99
  signing_key:
101
100
  specification_version: 4
102
101
  summary: ast node mutation apis
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # InsertAfterAction to insert code next to the node.
4
- class NodeMutation::InsertAfterAction < NodeMutation::Action
5
- private
6
-
7
- # Calculate the begin and end positions.
8
- def calculate_position
9
- @start = NodeMutation.adapter.get_end(@node)
10
- @end = @start
11
- end
12
-
13
- # Indent of the node.
14
- #
15
- # @param node [Parser::AST::Node]
16
- # @return [Integer] indent size
17
- def indent(node)
18
- ' ' * NodeMutation.adapter.get_start_loc(node).column
19
- end
20
- end