node_mutation 1.6.2 → 1.7.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/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 +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb6a1cb69d0fdb6691831450fae1c126d25ae38495f5b68725b7500708534671
|
4
|
+
data.tar.gz: 643999af6c57ea3553668945af32e49074605940c7372c6292272c34271672a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8088d0b9d08569fe3653a99c6a19ac7c5701b42a8e2d90668a5d1ea8cff354f5fe2f197ef319825f56ba0eeaef74380999a54fe84169818bc35bcc0263d11688
|
7
|
+
data.tar.gz: 55725a4fb619d3679531e4af3bbb098994b472b84b6aedecd5d88e9310959eda1c7ea261c76654b73963eb388cd786523bc1d58e561196b6a75cd024b912fcb4
|
data/CHANGELOG.md
CHANGED
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,7 +1,7 @@
|
|
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.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Huang
|
@@ -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
|