node_mutation 1.20.0 → 1.21.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: fd49bceca35429738e6137151b99634e0ef83801214ba58e80c5e1d67b299b07
4
- data.tar.gz: ef1f95f7edcf89b73b3eeb11137e374c813460cd4c5c8c67b970a5b29acc4e47
3
+ metadata.gz: 3bac003e717da366c7a0d9e1e0ee939db7173805fa2f9882b9141d089503cf00
4
+ data.tar.gz: 0e1a8f58718b689cb50bd5177496cc0b782594abff2b90cc532f3770fffce6fe
5
5
  SHA512:
6
- metadata.gz: 71f84423b7cc2edd182ce760c984c1fef78f17ca267c72fb02f2eea9674dad5cf7c284180e03dbb888b5872e1157110e656d1f3587df17fe72140110594f0665
7
- data.tar.gz: 951e9c6ba7afb239dab12428b40509e7d66178fe4776a317ebe5757a8d142e4fabe59ed1e75c5bedc4fe6a08e531c5176112cd48131b91422d1366e9d36af89a
6
+ metadata.gz: dee5df5d9cc61048b5b16b916527a8a031c80e16ff967bc547d65336a524bfd87e7135ebd72a8ac0aa1f3da6379520949c07d8a7c52baa13ea4a9d2a628c8318
7
+ data.tar.gz: 3252841fb0ec840591e21bcd28a5ab987271b6900664b7cd25397f7254d93130903d79f328763e67667bd5671101ec449e260a1a54b399939e5fdc9ff90910ff
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # NodeMutation
2
2
 
3
+ ## 1.21.0 (2023-09-26)
4
+
5
+ * Rename `combine` dsl to `group`
6
+
3
7
  ## 1.20.0 (2023-09-24)
4
8
 
5
9
  * Add `CombinedAction` to combine multiple actions.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- node_mutation (1.20.0)
4
+ node_mutation (1.21.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # CombinedAction combines multiple actions.
4
- class NodeMutation::CombinedAction < NodeMutation::Action
3
+ # GroupAction is compose of multiple actions.
4
+ class NodeMutation::GroupAction < NodeMutation::Action
5
5
  DEFAULT_START = 2**30
6
6
 
7
7
  attr_accessor :actions
8
8
 
9
9
  def initialize
10
10
  @actions = []
11
- @type = :combined
11
+ @type = :group
12
12
  end
13
13
 
14
14
  def new_code
@@ -4,7 +4,7 @@ class NodeMutation::Helper
4
4
  # It iterates over all actions, and calls the given block with each action.
5
5
  def self.iterate_actions(actions, &block)
6
6
  actions.each do |action|
7
- if action.is_a?(NodeMutation::CombinedAction)
7
+ if action.is_a?(NodeMutation::GroupAction)
8
8
  iterate_actions(action.actions, &block)
9
9
  else
10
10
  block.call(action)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class NodeMutation
4
- VERSION = "1.20.0"
4
+ VERSION = "1.21.0"
5
5
  end
data/lib/node_mutation.rb CHANGED
@@ -11,7 +11,7 @@ class NodeMutation
11
11
  autoload :SyntaxTreeAdapter, "node_mutation/adapter/syntax_tree"
12
12
  autoload :Action, 'node_mutation/action'
13
13
  autoload :AppendAction, 'node_mutation/action/append_action'
14
- autoload :CombinedAction, 'node_mutation/action/combined_action'
14
+ autoload :GroupAction, 'node_mutation/action/group_action'
15
15
  autoload :DeleteAction, 'node_mutation/action/delete_action'
16
16
  autoload :IndentAction, 'node_mutation/action/indent_action'
17
17
  autoload :InsertAction, 'node_mutation/action/insert_action'
@@ -210,13 +210,13 @@ class NodeMutation
210
210
  def wrap(node, prefix:, suffix:, newline: false)
211
211
  if newline
212
212
  indentation = NodeMutation.adapter.get_start_loc(node).column
213
- combine do
213
+ group do
214
214
  insert node, prefix + "\n" + (' ' * indentation), at: 'beginning'
215
215
  insert node, "\n" + (' ' * indentation) + suffix, at: 'end'
216
216
  indent node
217
217
  end
218
218
  else
219
- combine do
219
+ group do
220
220
  insert node, prefix, at: 'beginning'
221
221
  insert node, suffix, at: 'end'
222
222
  end
@@ -244,14 +244,14 @@ class NodeMutation
244
244
  @actions << NoopAction.new(node).process
245
245
  end
246
246
 
247
- # Combine multiple actions
248
- def combine
247
+ # group multiple actions
248
+ def group
249
249
  current_actions = @actions
250
- combined_action = CombinedAction.new
251
- @actions = combined_action.actions
250
+ group_action = GroupAction.new
251
+ @actions = group_action.actions
252
252
  yield
253
253
  @actions = current_actions
254
- @actions << combined_action.process
254
+ @actions << group_action.process
255
255
  end
256
256
 
257
257
  # Process actions and return the new source.
@@ -308,13 +308,13 @@ class NodeMutation
308
308
 
309
309
  private
310
310
 
311
- # It flattens a series of actions by removing any CombinedAction
311
+ # It flattens a series of actions by removing any GroupAction
312
312
  # objects that contain only a single action. This is done recursively.
313
313
  def flatten_actions(actions)
314
314
  new_actions = []
315
315
  actions.each do |action|
316
- if action.is_a?(CombinedAction)
317
- new_actions << flatten_combined_action(action)
316
+ if action.is_a?(GroupAction)
317
+ new_actions << flatten_group_action(action)
318
318
  else
319
319
  new_actions << action
320
320
  end
@@ -322,13 +322,13 @@ class NodeMutation
322
322
  new_actions.compact
323
323
  end
324
324
 
325
- # It flattens a combined action.
326
- def flatten_combined_action(action)
325
+ # It flattens a group action.
326
+ def flatten_group_action(action)
327
327
  if action.actions.empty?
328
328
  nil
329
329
  elsif action.actions.size == 1
330
- if action.actions.first.is_a?(CombinedAction)
331
- flatten_combined_action(action.actions.first)
330
+ if action.actions.first.is_a?(GroupAction)
331
+ flatten_group_action(action.actions.first)
332
332
  else
333
333
  action.actions.first
334
334
  end
@@ -344,7 +344,7 @@ class NodeMutation
344
344
  def sort_actions!(actions)
345
345
  actions.sort_by! { |action| [action.start, action.end] }
346
346
  actions.each do |action|
347
- sort_actions!(action.actions) if action.is_a?(CombinedAction)
347
+ sort_actions!(action.actions) if action.is_a?(GroupAction)
348
348
  end
349
349
  end
350
350
 
@@ -354,7 +354,7 @@ class NodeMutation
354
354
  # @return [String] new source code
355
355
  def rewrite_source(source, actions)
356
356
  actions.reverse_each do |action|
357
- if action.is_a?(CombinedAction)
357
+ if action.is_a?(GroupAction)
358
358
  source = rewrite_source(source, action.actions)
359
359
  else
360
360
  source[action.start...action.end] = action.new_code if action.new_code
@@ -385,7 +385,7 @@ class NodeMutation
385
385
  j -= 1
386
386
  end
387
387
  actions.each do |action|
388
- conflict_actions.concat(get_conflict_actions(action.actions)) if action.is_a?(CombinedAction)
388
+ conflict_actions.concat(get_conflict_actions(action.actions)) if action.is_a?(GroupAction)
389
389
  end
390
390
  conflict_actions
391
391
  end
@@ -39,7 +39,7 @@ class NodeMutation[T]
39
39
 
40
40
  def noop: (node: T) -> void
41
41
 
42
- def combine: () { () -> void } -> void
42
+ def group: () { () -> void } -> void
43
43
 
44
44
  def process: () -> NodeMutation::Result
45
45
 
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.20.0
4
+ version: 1.21.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: 2023-09-24 00:00:00.000000000 Z
11
+ date: 2023-09-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: ast node mutation apis
14
14
  email:
@@ -28,8 +28,8 @@ files:
28
28
  - lib/node_mutation.rb
29
29
  - lib/node_mutation/action.rb
30
30
  - lib/node_mutation/action/append_action.rb
31
- - lib/node_mutation/action/combined_action.rb
32
31
  - lib/node_mutation/action/delete_action.rb
32
+ - lib/node_mutation/action/group_action.rb
33
33
  - lib/node_mutation/action/indent_action.rb
34
34
  - lib/node_mutation/action/insert_action.rb
35
35
  - lib/node_mutation/action/noop_action.rb