node_mutation 1.23.0 → 1.23.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/Gemfile.lock +4 -4
- data/lib/node_mutation/adapter/prism.rb +7 -6
- data/lib/node_mutation/adapter/syntax_tree.rb +1 -0
- data/lib/node_mutation/version.rb +1 -1
- data/lib/node_mutation.rb +2 -0
- data/sig/node_mutation/struct.rbs +8 -8
- 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: 8428c48e2173db74d4ab6fca16ae15076106a021792ad2f24ff4e568a6d9af42
|
4
|
+
data.tar.gz: 4ffe5f7ebc5182b9a493bac7556a3ebe3bb140b435bad9df3529fc49b9e17315
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85f90dbcb989220b83677298a8606f7ac33a1db5db5e3d71bab5753e48c62d2f3dd3b7a40fdda548cd6f9fc1a5fe24fc6d4b285f78ecc06b8a1e29145a282bfc
|
7
|
+
data.tar.gz: c8ff9b11d12b5bdf7d2b550a48e55539abed67880f7b5a410f118f342001847b476b57600628906fe69ee410b8aca73dc9161cac979b45a98ef1eb4a07bd52ed
|
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.23.
|
4
|
+
node_mutation (1.23.2)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -40,8 +40,8 @@ GEM
|
|
40
40
|
parser_node_ext (1.2.2)
|
41
41
|
parser
|
42
42
|
prettier_print (1.2.1)
|
43
|
-
prism (0.
|
44
|
-
prism_ext (0.2.
|
43
|
+
prism (0.24.0)
|
44
|
+
prism_ext (0.2.3)
|
45
45
|
prism
|
46
46
|
pry (0.14.1)
|
47
47
|
coderay (~> 1.1)
|
@@ -67,7 +67,7 @@ GEM
|
|
67
67
|
shellany (0.0.1)
|
68
68
|
syntax_tree (6.2.0)
|
69
69
|
prettier_print (>= 1.2.0)
|
70
|
-
syntax_tree_ext (0.
|
70
|
+
syntax_tree_ext (0.7.2)
|
71
71
|
syntax_tree
|
72
72
|
thor (1.2.1)
|
73
73
|
|
@@ -6,10 +6,10 @@ require 'prism_ext'
|
|
6
6
|
class NodeMutation::PrismAdapter < NodeMutation::Adapter
|
7
7
|
def get_source(node)
|
8
8
|
if node.is_a?(Array)
|
9
|
-
return node.first.source[node.first.location.start_offset...node.last.location.end_offset]
|
9
|
+
return node.first.instance_variable_get(:@source).source[node.first.location.start_offset...node.last.location.end_offset]
|
10
10
|
end
|
11
11
|
|
12
|
-
node.
|
12
|
+
node.to_source
|
13
13
|
end
|
14
14
|
|
15
15
|
# It gets the new source code after evaluating the node.
|
@@ -92,7 +92,7 @@ class NodeMutation::PrismAdapter < NodeMutation::Adapter
|
|
92
92
|
end
|
93
93
|
|
94
94
|
def file_source(node)
|
95
|
-
node.source
|
95
|
+
node.instance_variable_get(:@source).source
|
96
96
|
end
|
97
97
|
|
98
98
|
# Get the range of the child node.
|
@@ -138,9 +138,9 @@ class NodeMutation::PrismAdapter < NodeMutation::Adapter
|
|
138
138
|
|
139
139
|
if node.respond_to?("#{child_name}_loc")
|
140
140
|
node_loc = node.send("#{child_name}_loc")
|
141
|
-
if node_loc
|
142
|
-
|
143
|
-
|
141
|
+
NodeMutation::Struct::Range.new(node_loc.start_offset, node_loc.end_offset) if node_loc
|
142
|
+
elsif node.is_a?(Prism::CallNode) && child_name.to_sym == :name
|
143
|
+
NodeMutation::Struct::Range.new(node.message_loc.start_offset, node.message_loc.end_offset)
|
144
144
|
else
|
145
145
|
raise NodeMutation::MethodNotSupported,
|
146
146
|
"#{direct_child_name} is not supported for #{get_source(node)}" unless node.respond_to?(direct_child_name)
|
@@ -150,6 +150,7 @@ class NodeMutation::PrismAdapter < NodeMutation::Adapter
|
|
150
150
|
return child_node_range(child_node, nested_child_name) if nested_child_name
|
151
151
|
|
152
152
|
return nil if child_node.nil?
|
153
|
+
return nil if child_node == []
|
153
154
|
|
154
155
|
if child_node.is_a?(Prism::Node)
|
155
156
|
return(
|
@@ -152,6 +152,7 @@ class NodeMutation::SyntaxTreeAdapter < NodeMutation::Adapter
|
|
152
152
|
return child_node_range(child_node, nested_child_name) if nested_child_name
|
153
153
|
|
154
154
|
return nil if child_node.nil?
|
155
|
+
return nil if child_node == []
|
155
156
|
|
156
157
|
if child_node.is_a?(SyntaxTree::Node)
|
157
158
|
return(
|
data/lib/node_mutation.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
class NodeMutation::Struct
|
2
2
|
class Action < ::Struct
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
attr_accessor type (): Symbol
|
4
|
+
attr_accessor start (): Integer
|
5
|
+
attr_accessor end (): Integer
|
6
|
+
attr_accessor new_code (): String
|
7
7
|
end
|
8
8
|
|
9
9
|
class Location < ::Struct
|
10
|
-
|
11
|
-
|
10
|
+
attr_accessor line (): Integer
|
11
|
+
attr_accessor column (): Integer
|
12
12
|
end
|
13
13
|
|
14
14
|
class Range < ::Struct
|
15
|
-
|
16
|
-
|
15
|
+
attr_accessor start (): Integer
|
16
|
+
attr_accessor end (): Integer
|
17
17
|
end
|
18
18
|
end
|
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.23.
|
4
|
+
version: 1.23.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Huang
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-02-
|
11
|
+
date: 2024-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: ast node mutation apis
|
14
14
|
email:
|