node_mutation 1.19.2 → 1.19.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 +4 -0
- data/Gemfile.lock +6 -4
- data/lib/node_mutation/adapter/parser.rb +2 -1
- data/lib/node_mutation/adapter/syntax_tree.rb +38 -7
- data/lib/node_mutation/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8089525a411cf3e7400148cba0d3cd21b763d6ec034dd5a627c0faf2419d8ec3
|
4
|
+
data.tar.gz: c5e0137f1da08ac49ffa45124cc39cb095543e5b5d5cc788e32093c581de2e2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ecd574ae42a8cabdee2bdae86a14b905fdb4df3205af93753de47e9eb86f595371332f7b9dc5c560c3cd0b48db45d41680784b44fa4be9fba7ef36eefa8d9a7
|
7
|
+
data.tar.gz: c67d25471f221f0c9d7bd1bd6c40c95c2dfc995154dd9264ce4268eb4990c380ca38c7732a5da6c1b75518c68aeb8e3ea32c644259de12ce01559abac722d63a
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
node_mutation (1.19.
|
4
|
+
node_mutation (1.19.3)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -34,14 +34,16 @@ GEM
|
|
34
34
|
notiffany (0.1.3)
|
35
35
|
nenv (~> 0.1)
|
36
36
|
shellany (~> 0.0)
|
37
|
-
parser (3.2.2.
|
37
|
+
parser (3.2.2.3)
|
38
38
|
ast (~> 2.4.1)
|
39
|
-
|
39
|
+
racc
|
40
|
+
parser_node_ext (1.2.0)
|
40
41
|
parser
|
41
42
|
prettier_print (1.2.1)
|
42
43
|
pry (0.14.1)
|
43
44
|
coderay (~> 1.1)
|
44
45
|
method_source (~> 1.0)
|
46
|
+
racc (1.7.1)
|
45
47
|
rake (13.0.6)
|
46
48
|
rb-fsevent (0.11.1)
|
47
49
|
rb-inotify (0.10.1)
|
@@ -62,7 +64,7 @@ GEM
|
|
62
64
|
shellany (0.0.1)
|
63
65
|
syntax_tree (6.1.1)
|
64
66
|
prettier_print (>= 1.2.0)
|
65
|
-
syntax_tree_ext (0.6.
|
67
|
+
syntax_tree_ext (0.6.3)
|
66
68
|
syntax_tree
|
67
69
|
thor (1.2.1)
|
68
70
|
|
@@ -177,6 +177,7 @@ class NodeMutation::ParserAdapter < NodeMutation::Adapter
|
|
177
177
|
end
|
178
178
|
when %i[class name], %i[const name], %i[cvar name], %i[def name], %i[defs name],
|
179
179
|
%i[gvar name], %i[ivar name], %i[lvar name]
|
180
|
+
|
180
181
|
NodeMutation::Struct::Range.new(node.loc.name.begin_pos, node.loc.name.end_pos)
|
181
182
|
when %i[const double_colon]
|
182
183
|
NodeMutation::Struct::Range.new(node.loc.double_colon.begin_pos, node.loc.double_colon.end_pos)
|
@@ -281,7 +282,7 @@ class NodeMutation::ParserAdapter < NodeMutation::Adapter
|
|
281
282
|
elsif direct_child_name == 'to_symbol' && node.type == :str
|
282
283
|
child_node = ":#{node.to_value}"
|
283
284
|
elsif direct_child_name == 'to_string' && node.type == :sym
|
284
|
-
|
285
|
+
child_node = node.to_value.to_s
|
285
286
|
elsif direct_child_name == 'to_single_quote' && node.type == :str
|
286
287
|
child_node = "'#{node.to_value}'"
|
287
288
|
elsif direct_child_name == 'to_double_quote' && node.type == :str
|
@@ -115,14 +115,28 @@ class NodeMutation::SyntaxTreeAdapter < NodeMutation::Adapter
|
|
115
115
|
# node = SyntaxTree::Parser.new('foo | bar').parse.statements.body.first
|
116
116
|
# child_node_range(node, 'operator') => { start: 'foo '.length, end: 'foo |'.length }
|
117
117
|
def child_node_range(node, child_name)
|
118
|
-
|
119
|
-
|
118
|
+
direct_child_name, nested_child_name = child_name.to_s.split('.', 2)
|
119
|
+
|
120
|
+
if node.is_a?(Array)
|
121
|
+
if direct_child_name =~ INDEX_REGEXP
|
122
|
+
child_node = node[direct_child_name.to_i]
|
123
|
+
raise NodeMutation::MethodNotSupported,
|
124
|
+
"#{direct_child_name} is not supported for #{get_source(node)}" unless child_node
|
125
|
+
return child_node_range(child_node, nested_child_name) if nested_child_name
|
126
|
+
|
127
|
+
return NodeMutation::Struct::Range.new(child_node.location.start_char, child_node.location.end_char)
|
128
|
+
end
|
129
|
+
|
130
|
+
raise NodeMutation::MethodNotSupported,
|
131
|
+
"#{direct_child_name} is not supported for #{get_source(node)}" unless node.respond_to?(direct_child_name)
|
132
|
+
|
133
|
+
child_node = node.send(direct_child_name)
|
134
|
+
return child_node_range(child_node, nested_child_name) if nested_child_name
|
120
135
|
|
121
|
-
|
122
|
-
return NodeMutation::Struct::Range.new(child_node.first.location.start_char, child_node.last.location.end_char)
|
136
|
+
return NodeMutation::Struct::Range.new(child_node.location.start_char, child_node.location.end_char)
|
123
137
|
end
|
124
138
|
|
125
|
-
if node.is_a?(SyntaxTree::Binary) && child_name ==
|
139
|
+
if node.is_a?(SyntaxTree::Binary) && child_name.to_sym == :operator
|
126
140
|
start_char = node.left.location.end_char
|
127
141
|
start_char += 1 while node.source[start_char] == ' '
|
128
142
|
end_char = node.right.location.start_char
|
@@ -130,7 +144,24 @@ class NodeMutation::SyntaxTreeAdapter < NodeMutation::Adapter
|
|
130
144
|
return NodeMutation::Struct::Range.new(start_char, end_char)
|
131
145
|
end
|
132
146
|
|
133
|
-
|
147
|
+
raise NodeMutation::MethodNotSupported,
|
148
|
+
"#{direct_child_name} is not supported for #{get_source(node)}" unless node.respond_to?(direct_child_name)
|
149
|
+
|
150
|
+
child_node = node.send(direct_child_name)
|
151
|
+
|
152
|
+
return child_node_range(child_node, nested_child_name) if nested_child_name
|
153
|
+
|
154
|
+
return nil if child_node.nil?
|
155
|
+
|
156
|
+
if child_node.is_a?(SyntaxTree::Node)
|
157
|
+
return(
|
158
|
+
NodeMutation::Struct::Range.new(child_node.location.start_char, child_node.location.end_char)
|
159
|
+
)
|
160
|
+
end
|
161
|
+
|
162
|
+
return(
|
163
|
+
NodeMutation::Struct::Range.new(child_node.first.location.start_char, child_node.last.location.end_char)
|
164
|
+
)
|
134
165
|
end
|
135
166
|
|
136
167
|
def get_start(node, child_name = nil)
|
@@ -195,7 +226,7 @@ class NodeMutation::SyntaxTreeAdapter < NodeMutation::Adapter
|
|
195
226
|
if node.block.block_var
|
196
227
|
child_node = "->(#{node.block.block_var.params.to_source}) {#{node.block.bodystmt.to_source}}"
|
197
228
|
else
|
198
|
-
child_node = "-> {#{node.block.bodystmt.to_source
|
229
|
+
child_node = "-> {#{node.block.bodystmt.to_source}}"
|
199
230
|
end
|
200
231
|
elsif direct_child_name == 'strip_curly_braces' && node.is_a?(SyntaxTree::HashLiteral)
|
201
232
|
child_node = node.to_source.sub(/^{(.*)}$/) { Regexp.last_match(1).strip }
|