node_mutation 1.13.1 → 1.14.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 +9 -0
- data/Gemfile.lock +1 -1
- data/lib/node_mutation/action.rb +3 -3
- data/lib/node_mutation/parser_adapter.rb +1 -1
- data/lib/node_mutation/version.rb +1 -1
- data/lib/node_mutation.rb +8 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5f41eba8034d3565eeda68905e0d6f8efff2a5ad56f0523f3aca6e57b334239
|
4
|
+
data.tar.gz: eb115a375da1d2e17ca62df7089ae22b243fc94e273b1a37378cc8ff215be6e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0bb8b60c6c9a822a883c2219303ba39bc649adade357ea82074cea9c4da8f0a33b6305bd45dc3e8b094a420b7f450dbd90fab80b498331e87c1a5fed8c68404
|
7
|
+
data.tar.gz: 69eab44d9cc1282ce4c7afb09a3ea80573728562538cbe75fde02458d915c5f8479c87098171d4421e5d157fac92a85f8ecce8b8c61bf29bd63dd6fd44a6128d
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# NodeMutation
|
2
2
|
|
3
|
+
## 1.14.0 (2023-04-04)
|
4
|
+
|
5
|
+
* Add `transform_proc` to transform the actions
|
6
|
+
* Allow to write `Action` `start` and `end` attributes
|
7
|
+
|
8
|
+
## 1.13.2 (2023-04-01)
|
9
|
+
|
10
|
+
* Support `cvar`, `gvar`, `ivar`, and `lvar` name in `child_node_range`
|
11
|
+
|
3
12
|
## 1.13.1 (2023-03-31)
|
4
13
|
|
5
14
|
* Remove both whitespaces only when next char is nil
|
data/Gemfile.lock
CHANGED
data/lib/node_mutation/action.rb
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
# Action defines rewriter action, insert, replace or delete code.
|
4
4
|
class NodeMutation::Action
|
5
|
-
# @!attribute [
|
5
|
+
# @!attribute [rw] start
|
6
6
|
# @return [Integer] start position
|
7
|
-
# @!attribute [
|
7
|
+
# @!attribute [rw] end
|
8
8
|
# @return [Integer] end position
|
9
|
-
|
9
|
+
attr_accessor :start, :end
|
10
10
|
|
11
11
|
# Initialize an action.
|
12
12
|
#
|
@@ -88,7 +88,7 @@ class NodeMutation::ParserAdapter < NodeMutation::Adapter
|
|
88
88
|
node.arguments.first.loc.expression.begin_pos,
|
89
89
|
node.arguments.last.loc.expression.end_pos
|
90
90
|
)
|
91
|
-
when %i[class name], %i[const name], %i[def name], %i[defs name]
|
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
93
|
when %i[defs dot]
|
94
94
|
NodeMutation::Struct::Range.new(node.loc.operator.begin_pos, node.loc.operator.end_pos) if node.loc.operator
|
data/lib/node_mutation.rb
CHANGED
@@ -22,8 +22,14 @@ class NodeMutation
|
|
22
22
|
autoload :Strategy, 'node_mutation/strategy'
|
23
23
|
autoload :Struct, 'node_mutation/struct'
|
24
24
|
|
25
|
+
# @!attribute [r] actions
|
26
|
+
# @return [Array<NodeMutation::Struct::Action>]
|
25
27
|
attr_reader :actions
|
26
28
|
|
29
|
+
# @!attribute [rw] transform_proc
|
30
|
+
# @return [Proc] proc to transfor the actions
|
31
|
+
attr_accessor :transform_proc
|
32
|
+
|
27
33
|
class << self
|
28
34
|
# Configure NodeMutation
|
29
35
|
# @param [Hash] options options to configure
|
@@ -219,6 +225,7 @@ class NodeMutation
|
|
219
225
|
end
|
220
226
|
|
221
227
|
source = +@source
|
228
|
+
@transform_proc.call(@actions) if @transform_proc
|
222
229
|
@actions.sort_by! { |action| [action.start, action.end] }
|
223
230
|
conflict_actions = get_conflict_actions
|
224
231
|
if conflict_actions.size > 0 && strategy?(Strategy::THROW_ERROR)
|
@@ -245,6 +252,7 @@ class NodeMutation
|
|
245
252
|
return NodeMutation::Result.new(affected: false, conflicted: false)
|
246
253
|
end
|
247
254
|
|
255
|
+
@transform_proc.call(@actions) if @transform_proc
|
248
256
|
@actions.sort_by! { |action| [action.start, action.end] }
|
249
257
|
conflict_actions = get_conflict_actions
|
250
258
|
if conflict_actions.size > 0 && strategy?(Strategy::THROW_ERROR)
|
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.14.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-
|
11
|
+
date: 2023-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: ast node mutation apis
|
14
14
|
email:
|