node_mutation 1.6.2 → 1.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/Gemfile.lock +1 -1
- data/lib/node_mutation/parser_adapter.rb +2 -0
- data/lib/node_mutation/strategy.rb +7 -0
- data/lib/node_mutation/version.rb +1 -1
- data/lib/node_mutation.rb +11 -9
- data/sig/node_mutation.rbs +2 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9dffabe82f3653964c889ce43ccf443348973e9868c1c7565327ae253d0be08d
|
4
|
+
data.tar.gz: 1b72a6361aea2795c06881754bb8822caf069d8f0b54e9f9e0e8685f70de4b21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc5969cdfdf5654fe4c6886b5d177e356d2072b1369bd0eb7c75b59d60d3388b1dfaf69a435e13e5d1e46006ec9368e1aedeca4b82af29e61bb1525d19a2c428
|
7
|
+
data.tar.gz: 6db8711936e7f6772bf44afefda33c8969ea9ffdd3db05a80fcc414958efb2b22b24ce373d1c45950f8118b13de72fdc091b6b2d6213d3912ab7a34704078de1
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# NodeMutation
|
2
2
|
|
3
|
+
## 1.7.1 (2022-10-26)
|
4
|
+
|
5
|
+
* Return empty string for `NilClass` in `ParserAdapter#rewritten_source`
|
6
|
+
|
7
|
+
## 1.7.0 (2022-10-25)
|
8
|
+
|
9
|
+
* Add a new strategy `ALLOW_INSERT_AT_SAME_POSITION`
|
10
|
+
|
3
11
|
## 1.6.2 (2022-10-25)
|
4
12
|
|
5
13
|
* Mark same position as conflict action
|
data/Gemfile.lock
CHANGED
data/lib/node_mutation.rb
CHANGED
@@ -9,9 +9,6 @@ class NodeMutation
|
|
9
9
|
class MethodNotSupported < StandardError; end
|
10
10
|
class ConflictActionError < StandardError; end
|
11
11
|
|
12
|
-
KEEP_RUNNING = 1
|
13
|
-
THROW_ERROR = 2
|
14
|
-
|
15
12
|
autoload :Adapter, "node_mutation/adapter"
|
16
13
|
autoload :ParserAdapter, "node_mutation/parser_adapter"
|
17
14
|
autoload :Action, 'node_mutation/action'
|
@@ -25,6 +22,7 @@ class NodeMutation
|
|
25
22
|
autoload :WrapAction, 'node_mutation/action/wrap_action'
|
26
23
|
autoload :NoopAction, 'node_mutation/action/noop_action'
|
27
24
|
autoload :Result, 'node_mutation/result'
|
25
|
+
autoload :Strategy, 'node_mutation/strategy'
|
28
26
|
|
29
27
|
attr_reader :actions
|
30
28
|
|
@@ -47,10 +45,10 @@ class NodeMutation
|
|
47
45
|
end
|
48
46
|
|
49
47
|
# Get the strategy
|
50
|
-
# @return [Integer] current strategy, could be {NodeMutation::KEEP_RUNNING} or {NodeMutation::THROW_ERROR},
|
51
|
-
# by default is {NodeMutation::KEEP_RUNNING}
|
48
|
+
# @return [Integer] current strategy, could be {NodeMutation::Strategy::KEEP_RUNNING} or {NodeMutation::Strategy::THROW_ERROR},
|
49
|
+
# by default is {NodeMutation::Strategy::KEEP_RUNNING}
|
52
50
|
def self.strategy
|
53
|
-
@strategy ||= KEEP_RUNNING
|
51
|
+
@strategy ||= Strategy::KEEP_RUNNING
|
54
52
|
end
|
55
53
|
|
56
54
|
# Initialize a NodeMutation.
|
@@ -214,7 +212,7 @@ class NodeMutation
|
|
214
212
|
source = +@source
|
215
213
|
@actions.sort_by! { |action| [action.start, action.end] }
|
216
214
|
conflict_actions = get_conflict_actions
|
217
|
-
if conflict_actions.size > 0 &&
|
215
|
+
if conflict_actions.size > 0 && strategy?(Strategy::THROW_ERROR)
|
218
216
|
raise ConflictActionError, "mutation actions are conflicted"
|
219
217
|
end
|
220
218
|
@actions.reverse_each do |action|
|
@@ -242,7 +240,7 @@ class NodeMutation
|
|
242
240
|
conflict_actions = []
|
243
241
|
@actions.sort_by! { |action| [action.start, action.end] }
|
244
242
|
conflict_actions = get_conflict_actions
|
245
|
-
if conflict_actions.size > 0 &&
|
243
|
+
if conflict_actions.size > 0 && strategy?(Strategy::THROW_ERROR)
|
246
244
|
raise ConflictActionError, "mutation actions are conflicted"
|
247
245
|
end
|
248
246
|
NodeMutation::Result.new(
|
@@ -269,7 +267,7 @@ class NodeMutation
|
|
269
267
|
same_position = begin_pos == @actions[j].start && begin_pos == end_pos && @actions[j].start == @actions[j].end
|
270
268
|
# if we have two actions with overlapped range.
|
271
269
|
overlapped_position = begin_pos < @actions[j].end
|
272
|
-
if same_position || overlapped_position
|
270
|
+
if (!strategy?(Strategy::ALLOW_INSERT_AT_SAME_POSITION) && same_position) || overlapped_position
|
273
271
|
conflict_actions << @actions.delete_at(j)
|
274
272
|
else
|
275
273
|
i = j
|
@@ -281,6 +279,10 @@ class NodeMutation
|
|
281
279
|
conflict_actions
|
282
280
|
end
|
283
281
|
|
282
|
+
def strategy?(strategy)
|
283
|
+
NodeMutation.strategy & strategy == strategy
|
284
|
+
end
|
285
|
+
|
284
286
|
def format_actions(actions)
|
285
287
|
actions.map { |action| OpenStruct.new(start: action.start, end: action.end, new_code: action.new_code ) }
|
286
288
|
end
|
data/sig/node_mutation.rbs
CHANGED
@@ -13,11 +13,11 @@ module NodeMutation[T]
|
|
13
13
|
|
14
14
|
attr_reader actions: Array[NodeMutation::Action]
|
15
15
|
|
16
|
-
def self.configure: (options: { adapter: NodeMutation::Adapter,
|
16
|
+
def self.configure: (options: { adapter: NodeMutation::Adapter, strategy: Integer }) -> void
|
17
17
|
|
18
18
|
def self.adapter: () -> NodeMutation::Adapter
|
19
19
|
|
20
|
-
def self.
|
20
|
+
def self.strategy: () -> Integer
|
21
21
|
|
22
22
|
def initialize: (source: String) -> NodeMutation
|
23
23
|
|
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.7.1
|
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-10-
|
11
|
+
date: 2022-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- lib/node_mutation/engine/erb.rb
|
70
70
|
- lib/node_mutation/parser_adapter.rb
|
71
71
|
- lib/node_mutation/result.rb
|
72
|
+
- lib/node_mutation/strategy.rb
|
72
73
|
- lib/node_mutation/version.rb
|
73
74
|
- node_mutation.gemspec
|
74
75
|
- sig/node_mutation.rbs
|