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 +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/lib/node_mutation/action/{combined_action.rb → group_action.rb} +3 -3
- data/lib/node_mutation/helper.rb +1 -1
- data/lib/node_mutation/version.rb +1 -1
- data/lib/node_mutation.rb +18 -18
- data/sig/node_mutation.rbs +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3bac003e717da366c7a0d9e1e0ee939db7173805fa2f9882b9141d089503cf00
|
4
|
+
data.tar.gz: 0e1a8f58718b689cb50bd5177496cc0b782594abff2b90cc532f3770fffce6fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dee5df5d9cc61048b5b16b916527a8a031c80e16ff967bc547d65336a524bfd87e7135ebd72a8ac0aa1f3da6379520949c07d8a7c52baa13ea4a9d2a628c8318
|
7
|
+
data.tar.gz: 3252841fb0ec840591e21bcd28a5ab987271b6900664b7cd25397f7254d93130903d79f328763e67667bd5671101ec449e260a1a54b399939e5fdc9ff90910ff
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
4
|
-
class NodeMutation::
|
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 = :
|
11
|
+
@type = :group
|
12
12
|
end
|
13
13
|
|
14
14
|
def new_code
|
data/lib/node_mutation/helper.rb
CHANGED
@@ -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::
|
7
|
+
if action.is_a?(NodeMutation::GroupAction)
|
8
8
|
iterate_actions(action.actions, &block)
|
9
9
|
else
|
10
10
|
block.call(action)
|
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 :
|
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
|
-
|
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
|
-
|
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
|
-
#
|
248
|
-
def
|
247
|
+
# group multiple actions
|
248
|
+
def group
|
249
249
|
current_actions = @actions
|
250
|
-
|
251
|
-
@actions =
|
250
|
+
group_action = GroupAction.new
|
251
|
+
@actions = group_action.actions
|
252
252
|
yield
|
253
253
|
@actions = current_actions
|
254
|
-
@actions <<
|
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
|
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?(
|
317
|
-
new_actions <<
|
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
|
326
|
-
def
|
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?(
|
331
|
-
|
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?(
|
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?(
|
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?(
|
388
|
+
conflict_actions.concat(get_conflict_actions(action.actions)) if action.is_a?(GroupAction)
|
389
389
|
end
|
390
390
|
conflict_actions
|
391
391
|
end
|
data/sig/node_mutation.rbs
CHANGED
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
|
+
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-
|
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
|