node_mutation 1.11.0 → 1.12.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/parser_adapter.rb +48 -32
- data/lib/node_mutation/version.rb +1 -1
- 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: 97dd9f7362d033a9572811a001fcda89634580d2af15bd7736209dbb7228ba56
|
4
|
+
data.tar.gz: e7d4eb04cd7c0d739622105b8aedf85bc8e1e72c8e4e278bf87d840d05787fea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e44b67cb7c1dc8ef15ed16ac92c10400639704df32d0a06f2db40a68b8ea6259fe73d7c0dda2df8c5dd07c03137e95d7eca62ae0948c27b2e93b36fa5752cc3
|
7
|
+
data.tar.gz: f07ebe6b3712ae3d13b9cf06b7b5dd3e45d68ee7cb7571a9e227f2318de16271f4db2aea0a1ec62a48bc71e6666f8c91e9fda00628cf32d685af083890f70b41
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -17,41 +17,36 @@ class NodeMutation::ParserAdapter < NodeMutation::Adapter
|
|
17
17
|
def rewritten_source(node, code)
|
18
18
|
code.gsub(/{{(.+?)}}/m) do
|
19
19
|
old_code = Regexp.last_match(1)
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
evaluated = child_node_by_name(node, old_code)
|
21
|
+
case evaluated
|
22
|
+
when Parser::AST::Node
|
23
|
+
if evaluated.type == :args
|
24
|
+
evaluated.loc.expression.source[1...-1]
|
25
|
+
else
|
26
|
+
evaluated.loc.expression.source
|
27
|
+
end
|
28
|
+
when Array
|
29
|
+
if evaluated.size > 0
|
30
|
+
file_source = file_content(evaluated.first)
|
31
|
+
source = file_source[evaluated.first.loc.expression.begin_pos...evaluated.last.loc.expression.end_pos]
|
32
|
+
lines = source.split "\n"
|
33
|
+
lines_count = lines.length
|
34
|
+
if lines_count > 1 && lines_count == evaluated.size
|
35
|
+
new_code = []
|
36
|
+
lines.each_with_index { |line, index|
|
37
|
+
new_code << (index == 0 ? line : line[evaluated.first.indent - 2..-1])
|
38
|
+
}
|
39
|
+
new_code.join("\n")
|
27
40
|
else
|
28
|
-
|
41
|
+
source
|
29
42
|
end
|
30
|
-
when Array
|
31
|
-
if evaluated.size > 0
|
32
|
-
file_source = file_content(evaluated.first)
|
33
|
-
source = file_source[evaluated.first.loc.expression.begin_pos...evaluated.last.loc.expression.end_pos]
|
34
|
-
lines = source.split "\n"
|
35
|
-
lines_count = lines.length
|
36
|
-
if lines_count > 1 && lines_count == evaluated.size
|
37
|
-
new_code = []
|
38
|
-
lines.each_with_index { |line, index|
|
39
|
-
new_code << (index == 0 ? line : line[evaluated.first.indent - 2..-1])
|
40
|
-
}
|
41
|
-
new_code.join("\n")
|
42
|
-
else
|
43
|
-
source
|
44
|
-
end
|
45
|
-
end
|
46
|
-
when String, Symbol, Integer, Float
|
47
|
-
evaluated
|
48
|
-
when NilClass
|
49
|
-
''
|
50
|
-
else
|
51
|
-
raise "can not parse \"#{code}\""
|
52
43
|
end
|
44
|
+
when String, Symbol, Integer, Float
|
45
|
+
evaluated
|
46
|
+
when NilClass
|
47
|
+
''
|
53
48
|
else
|
54
|
-
raise
|
49
|
+
raise "can not parse \"#{code}\""
|
55
50
|
end
|
56
51
|
end
|
57
52
|
end
|
@@ -84,7 +79,10 @@ class NodeMutation::ParserAdapter < NodeMutation::Adapter
|
|
84
79
|
|
85
80
|
case [node.type, child_name.to_sym]
|
86
81
|
when %i[block pipes], %i[def parentheses], %i[defs parentheses]
|
87
|
-
NodeMutation::Range.new(
|
82
|
+
NodeMutation::Range.new(
|
83
|
+
node.arguments.first.loc.expression.begin_pos - 1,
|
84
|
+
node.arguments.last.loc.expression.end_pos + 1
|
85
|
+
)
|
88
86
|
when %i[block arguments], %i[def arguments], %i[defs arguments]
|
89
87
|
NodeMutation::Range.new(node.arguments.first.loc.expression.begin_pos, node.arguments.last.loc.expression.end_pos)
|
90
88
|
when %i[class name], %i[const name], %i[def name], %i[defs name]
|
@@ -108,6 +106,15 @@ class NodeMutation::ParserAdapter < NodeMutation::Adapter
|
|
108
106
|
NodeMutation::Range.new(node.loc.begin.begin_pos, node.loc.end.end_pos)
|
109
107
|
end
|
110
108
|
else
|
109
|
+
if node.type == :hash && child_name.to_s.end_with?('_pair')
|
110
|
+
pair_node = node.pairs.find { |pair| pair.key.to_value.to_s == child_name.to_s[0..-6] }
|
111
|
+
raise NodeMutation::MethodNotSupported,
|
112
|
+
"#{direct_child_name} is not supported for #{get_source(node)}" unless pair_node
|
113
|
+
return child_node_range(pair, nested_child_name) if nested_child_name
|
114
|
+
|
115
|
+
return NodeMutation::Range.new(pair_node.loc.expression.begin_pos, pair_node.loc.expression.end_pos)
|
116
|
+
end
|
117
|
+
|
111
118
|
raise NodeMutation::MethodNotSupported,
|
112
119
|
"#{direct_child_name} is not supported for #{get_source(node)}" unless node.respond_to?(direct_child_name)
|
113
120
|
|
@@ -178,6 +185,15 @@ class NodeMutation::ParserAdapter < NodeMutation::Adapter
|
|
178
185
|
return child_node
|
179
186
|
end
|
180
187
|
|
188
|
+
if node.is_a?(Parser::AST::Node) && node.type == :hash && direct_child_name.end_with?('_pair')
|
189
|
+
pair_node = node.pairs.find { |pair| pair.key.to_value.to_s == direct_child_name[0..-6] }
|
190
|
+
raise NodeMutation::MethodNotSupported,
|
191
|
+
"#{direct_child_name} is not supported for #{get_source(node)}" unless pair_node
|
192
|
+
return child_node_by_name(pair_node, nested_child_name) if nested_child_name
|
193
|
+
|
194
|
+
return pair_node
|
195
|
+
end
|
196
|
+
|
181
197
|
if node.respond_to?(direct_child_name)
|
182
198
|
child_node = node.send(direct_child_name)
|
183
199
|
elsif direct_child_name.include?('(') && direct_child_name.include?(')')
|
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.12.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-03-
|
11
|
+
date: 2023-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: erubis
|