node_mutation 1.18.1 → 1.18.3
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/action/indent_action.rb +2 -1
- data/lib/node_mutation/action/prepend_action.rb +1 -3
- data/lib/node_mutation/adapter/parser.rb +3 -1
- data/lib/node_mutation/result.rb +4 -1
- data/lib/node_mutation/version.rb +1 -1
- data/lib/node_mutation.rb +2 -2
- data/sig/node_mutation/struct.rbs +8 -8
- data/sig/node_mutation.rbs +3 -3
- 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: f841956c32adce81a0124670b81a180dc1a5c607946de843ee4ffb18df46eb59
|
4
|
+
data.tar.gz: 1f962b025780338e39f674d1a130a42ab85b7ed499630e77151ffb8cf8fcfbdc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a67239ac105f6ba64aa52a67c228310e4b13a8b2f0076343f006faf562c0a4cf00d3eb83212fdd75d3c63421c8763a67a1afb2c067dceaf9e1fcd25d8fb935e5
|
7
|
+
data.tar.gz: 0b6c56d6114b997743a33e96c19976ceb9cdc15c0e1b515acf092e1275149c5ddb93359707700cca9b274decf1e73690ed12b23c8280eccda1500e9a5e88ccf4
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -17,7 +17,8 @@ class NodeMutation::IndentAction < NodeMutation::Action
|
|
17
17
|
# @return [String] rewritten code.
|
18
18
|
def new_code
|
19
19
|
source = NodeMutation.adapter.get_source(@node)
|
20
|
-
source.each_line.map { |line| ' ' * NodeMutation.tab_width * @tab_size + line }
|
20
|
+
source.each_line.map { |line| (' ' * NodeMutation.tab_width * @tab_size) + line }
|
21
|
+
.join
|
21
22
|
end
|
22
23
|
|
23
24
|
private
|
@@ -9,14 +9,12 @@ class NodeMutation::PrependAction < NodeMutation::Action
|
|
9
9
|
|
10
10
|
private
|
11
11
|
|
12
|
-
DO_LENGTH = ' do'.length
|
13
|
-
|
14
12
|
# Calculate the begin and end positions.
|
15
13
|
def calculate_position
|
16
14
|
node_start = NodeMutation.adapter.get_start(@node)
|
17
15
|
node_source = NodeMutation.adapter.get_source(@node)
|
18
16
|
first_line = node_source.split("\n").first
|
19
|
-
@start = first_line.end_with?("do") ? node_start + first_line.
|
17
|
+
@start = first_line.end_with?("do") ? node_start + first_line.rindex("do") + "do".length : node_start + first_line.length
|
20
18
|
@end = @start
|
21
19
|
end
|
22
20
|
|
@@ -106,7 +106,9 @@ class NodeMutation::ParserAdapter < NodeMutation::Adapter
|
|
106
106
|
node.body.last.loc.expression.end_pos
|
107
107
|
)
|
108
108
|
end
|
109
|
-
when %i[class name], %i[const name], %i[cvar name], %i[def name], %i[defs name],
|
109
|
+
when %i[class name], %i[const name], %i[cvar name], %i[def name], %i[defs name],
|
110
|
+
%i[gvar name], %i[ivar name], %i[lvar name]
|
111
|
+
|
110
112
|
NodeMutation::Struct::Range.new(node.loc.name.begin_pos, node.loc.name.end_pos)
|
111
113
|
when %i[const double_colon]
|
112
114
|
NodeMutation::Struct::Range.new(node.loc.double_colon.begin_pos, node.loc.double_colon.end_pos)
|
data/lib/node_mutation/result.rb
CHANGED
@@ -19,7 +19,10 @@ class NodeMutation::Result
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def actions=(actions)
|
22
|
-
@actions =
|
22
|
+
@actions =
|
23
|
+
actions.map { |action|
|
24
|
+
NodeMutation::Struct::Action.new(action.type, action.start, action.end, action.new_code)
|
25
|
+
}
|
23
26
|
end
|
24
27
|
|
25
28
|
def to_json(*args)
|
data/lib/node_mutation.rb
CHANGED
@@ -208,8 +208,8 @@ class NodeMutation
|
|
208
208
|
def wrap(node, prefix:, suffix:, newline: false)
|
209
209
|
if newline
|
210
210
|
indentation = NodeMutation.adapter.get_start_loc(node).column
|
211
|
-
@actions << InsertAction.new(node, prefix + "\n" + ' ' * indentation, at: 'beginning').process
|
212
|
-
@actions << InsertAction.new(node, "\n" + ' ' * indentation + suffix, at: 'end').process
|
211
|
+
@actions << InsertAction.new(node, prefix + "\n" + (' ' * indentation), at: 'beginning').process
|
212
|
+
@actions << InsertAction.new(node, "\n" + (' ' * indentation) + suffix, at: 'end').process
|
213
213
|
@actions << IndentAction.new(node).process
|
214
214
|
else
|
215
215
|
@actions << InsertAction.new(node, prefix, at: 'beginning').process
|
@@ -1,18 +1,18 @@
|
|
1
1
|
class NodeMutation::Struct
|
2
2
|
class Action < ::Struct
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
atr_accessor type (): Symbol
|
4
|
+
atr_accessor start (): Integer
|
5
|
+
atr_accessor end (): Integer
|
6
|
+
atr_accessor new_code (): String
|
7
7
|
end
|
8
8
|
|
9
9
|
class Location < ::Struct
|
10
|
-
|
11
|
-
|
10
|
+
atr_accessor line (): Integer
|
11
|
+
atr_accessor column (): Integer
|
12
12
|
end
|
13
13
|
|
14
14
|
class Range < ::Struct
|
15
|
-
|
16
|
-
|
15
|
+
atr_accessor start (): Integer
|
16
|
+
atr_accessor end (): Integer
|
17
17
|
end
|
18
18
|
end
|
data/sig/node_mutation.rbs
CHANGED
@@ -21,7 +21,7 @@ module NodeMutation[T]
|
|
21
21
|
|
22
22
|
def append: (node: T, code: String) -> void
|
23
23
|
|
24
|
-
def delete: (node: T,
|
24
|
+
def delete: (node: T, selectors: Array[String], and_comma: bool) -> void
|
25
25
|
|
26
26
|
def indent: (node: T, ?tab_size: Integer) -> void
|
27
27
|
|
@@ -29,9 +29,9 @@ module NodeMutation[T]
|
|
29
29
|
|
30
30
|
def prepend: (node: T, code: String) -> void
|
31
31
|
|
32
|
-
def remove: (node: T,
|
32
|
+
def remove: (node: T, and_comma: bool) -> void
|
33
33
|
|
34
|
-
def replace: (node: T,
|
34
|
+
def replace: (node: T, selectors: Array[String], with: String) -> void
|
35
35
|
|
36
36
|
def replace_with: (node: T, code: String) -> void
|
37
37
|
|
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.18.
|
4
|
+
version: 1.18.3
|
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-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: ast node mutation apis
|
14
14
|
email:
|