node_mutation 1.15.0 → 1.15.2

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: 11054e72fcf35b7caeb2cee67b421206da2f980d4d1f23afa08f9db75f112f75
4
- data.tar.gz: 4dde234a2f4716b82d042b7d9f094469da04942cdca669c40a7d745f75480b77
3
+ metadata.gz: 3fadeda3c2cf8d3f0d618b4a9996241619ab404fef419e87026a443c8078e06f
4
+ data.tar.gz: 39d9939b21c96821ce056ad1983b301d16fc1d49c936ce082e3b208a6a93547c
5
5
  SHA512:
6
- metadata.gz: 5bfc255f3b2bf599debc4c8d882999d3083f89ec2e9cdb81aa2eb1d4245e65cafb61c9f9ee7db7286b4efddf66b96cb00742696f5215beab1b3cc847c2025b40
7
- data.tar.gz: 7c9063056156b1ee4accd50ad204040209c55ca096f543ecccc5f66175b1213a5611a4815263058514d81466e440d6cdf36f65c7208d048c48c3f3736e516706
6
+ metadata.gz: bdbfe2e830ef226679fa3556b52a23f67755afb2e33a7f8efaf5bd47e4f0e1d59f3b43af99bf4542587b2c9eee832a5309f0531689cc98cb954e38ca03bc0edc
7
+ data.tar.gz: b9b9d033e38d84f4672cdb3630d44f8179af09ceb268b25d9e88fe3a86eff97d543f710d3f0c3ecbb3f8a2c22c45de2998a02b32b454dd2eff08d6d907ba4f4e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # NodeMutation
2
2
 
3
+ ## 1.15.2 (2023-04-17)
4
+
5
+ * Support `const` `double_colon` in child_node_range
6
+
7
+ ## 1.15.1 (2023-04-17)
8
+
9
+ * Fix `wrap` code for newline
10
+
3
11
  ## 1.15.0 (2023-04-17)
4
12
 
5
13
  * Add `indent` action
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- node_mutation (1.15.0)
4
+ node_mutation (1.15.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -90,6 +90,8 @@ class NodeMutation::ParserAdapter < NodeMutation::Adapter
90
90
  )
91
91
  when %i[class name], %i[const name], %i[cvar name], %i[def name], %i[defs name], %i[gvar name], %i[ivar name], %i[lvar name]
92
92
  NodeMutation::Struct::Range.new(node.loc.name.begin_pos, node.loc.name.end_pos)
93
+ when %i[const double_colon]
94
+ NodeMutation::Struct::Range.new(node.loc.double_colon.begin_pos, node.loc.double_colon.end_pos)
93
95
  when %i[defs dot]
94
96
  NodeMutation::Struct::Range.new(node.loc.operator.begin_pos, node.loc.operator.end_pos) if node.loc.operator
95
97
  when %i[defs self]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class NodeMutation
4
- VERSION = "1.15.0"
4
+ VERSION = "1.15.2"
5
5
  end
data/lib/node_mutation.rb CHANGED
@@ -205,9 +205,15 @@ class NodeMutation
205
205
  # end
206
206
  # end
207
207
  def wrap(node, prefix:, suffix:, newline: false)
208
- @actions << InsertAction.new(node, prefix, at: 'beginning').process
209
- @actions << InsertAction.new(node, suffix, at: 'end').process
210
- @actions << IndentAction.new(node).process if newline
208
+ if newline
209
+ indentation = NodeMutation.adapter.get_start_loc(node).column
210
+ @actions << InsertAction.new(node, prefix + "\n" + ' ' * indentation, at: 'beginning').process
211
+ @actions << InsertAction.new(node, "\n" + ' ' * indentation + suffix, at: 'end').process
212
+ @actions << IndentAction.new(node).process
213
+ else
214
+ @actions << InsertAction.new(node, prefix, at: 'beginning').process
215
+ @actions << InsertAction.new(node, suffix, at: 'end').process
216
+ end
211
217
  end
212
218
 
213
219
  # No operation.
@@ -23,6 +23,8 @@ module NodeMutation[T]
23
23
 
24
24
  def delete: (node: T, *selectors: Array[String], **options: { and_comma: bool }) -> void
25
25
 
26
+ def indent: (node: T, ?tab_size: Integer) -> void
27
+
26
28
  def insert: (node: T, code: String, ?at: "beginning" | "end", ?to: nil | String) -> void
27
29
 
28
30
  def prepend: (node: T, code: String) -> void
@@ -33,7 +35,7 @@ module NodeMutation[T]
33
35
 
34
36
  def replace_with: (node: T, code: String) -> void
35
37
 
36
- def wrap: (node: T, with: String) -> void
38
+ def wrap: (node: T, prefix: String, suffix: String, ?newline: bool) -> void
37
39
 
38
40
  def noop: (node: T) -> void
39
41
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: node_mutation
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.15.0
4
+ version: 1.15.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang