node_mutation 1.24.3 → 1.24.4
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 +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +10 -2
- data/lib/node_mutation/adapter/prism.rb +12 -12
- 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: 5fbc8f86a01844e6cefbdc699124dfaef0fa8da5581a4375a4f99132efdc0bbf
|
4
|
+
data.tar.gz: 8868c51bced5f0ec6a4dfb52951989ba7dc1e5fad389c9be2d3d96303346e490
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 808c1a596e88980cdbdaab4c8c6fda0e7d21431f4bbb2529a79c1cddaa4fe51f09eadba2ed5a90e6f8f8c8d3c4fd1396a906a4f0cc8398bbf497b35068204390
|
7
|
+
data.tar.gz: 6999f0fb1490422a929d9faa2de9daec7ada538fd17c27b6f6f5c19655068a08a5ed87c07a8aec49ab5ef8440353c914d4fc38136087af4cb1601384df4745ff
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -84,16 +84,24 @@ mutation.replace node, '{{arguments.-1.on_value}}', with: ':update'
|
|
84
84
|
source # after_commit :do_index, on: :update, if: :indexable?
|
85
85
|
```
|
86
86
|
|
87
|
-
See more in [
|
87
|
+
See more in [PrismAdapter](https://synvert-hq.github.io/node-mutation-ruby/NodeMutation/PrismAdapter.html)
|
88
|
+
and [ParserAdapter](https://synvert-hq.github.io/node-mutation-ruby/NodeMutation/ParserAdapter.html)
|
89
|
+
and [SyntaxTreeAdapter](https://synvert-hq.github.io/node-mutation-ruby/NodeMutation/SyntaxTreeAdapter.html)
|
88
90
|
|
89
91
|
## Configuration
|
90
92
|
|
91
93
|
### adapter
|
92
94
|
|
93
|
-
Different parsers, like parse and
|
95
|
+
Different parsers, like prism, parse and syntax_tree, will generate different AST nodes, to make NodeMutation work for them all,
|
94
96
|
we define an [Adapter](https://github.com/synvert-hq/node-mutation-ruby/blob/main/lib/node_mutation/adapter.rb) interface,
|
95
97
|
if you implement the Adapter interface, you can set it as NodeMutation's adapter.
|
96
98
|
|
99
|
+
It provides 3 adapters
|
100
|
+
|
101
|
+
1. `PrismAdapter`
|
102
|
+
2. `ParserAdapter`
|
103
|
+
3. `SyntaxTreeAdapter`
|
104
|
+
|
97
105
|
### strategy
|
98
106
|
|
99
107
|
It provides 3 strategies to handle conflicts when processing actions:
|
@@ -6,7 +6,7 @@ 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.instance_variable_get(:@source).source[node.first.location.
|
9
|
+
return node.first.instance_variable_get(:@source).source[node.first.location.start_character_offset...node.last.location.end_character_offset]
|
10
10
|
end
|
11
11
|
|
12
12
|
node.to_source
|
@@ -124,7 +124,7 @@ class NodeMutation::PrismAdapter < NodeMutation::Adapter
|
|
124
124
|
"#{direct_child_name} is not supported for #{get_source(node)}" unless child_node
|
125
125
|
return child_node_range(child_node, nested_child_name) if nested_child_name
|
126
126
|
|
127
|
-
return NodeMutation::Struct::Range.new(child_node.location.
|
127
|
+
return NodeMutation::Struct::Range.new(child_node.location.start_character_offset, child_node.location.end_character_offset)
|
128
128
|
end
|
129
129
|
|
130
130
|
raise NodeMutation::MethodNotSupported,
|
@@ -133,16 +133,16 @@ class NodeMutation::PrismAdapter < NodeMutation::Adapter
|
|
133
133
|
child_node = node.send(direct_child_name)
|
134
134
|
return child_node_range(child_node, nested_child_name) if nested_child_name
|
135
135
|
|
136
|
-
return NodeMutation::Struct::Range.new(child_node.location.
|
136
|
+
return NodeMutation::Struct::Range.new(child_node.location.start_character_offset, child_node.location.end_character_offset)
|
137
137
|
end
|
138
138
|
|
139
139
|
if node.respond_to?("#{child_name}_loc")
|
140
140
|
node_loc = node.send("#{child_name}_loc")
|
141
|
-
NodeMutation::Struct::Range.new(node_loc.
|
141
|
+
NodeMutation::Struct::Range.new(node_loc.start_character_offset, node_loc.end_character_offset) if node_loc
|
142
142
|
elsif node.is_a?(Prism::CallNode) && child_name.to_sym == :name
|
143
|
-
NodeMutation::Struct::Range.new(node.message_loc.
|
143
|
+
NodeMutation::Struct::Range.new(node.message_loc.start_character_offset, node.message_loc.end_character_offset)
|
144
144
|
elsif node.is_a?(Prism::LocalVariableReadNode) && child_name.to_sym == :name
|
145
|
-
NodeMutation::Struct::Range.new(node.location.
|
145
|
+
NodeMutation::Struct::Range.new(node.location.start_character_offset, node.location.end_character_offset)
|
146
146
|
else
|
147
147
|
raise NodeMutation::MethodNotSupported,
|
148
148
|
"#{direct_child_name} is not supported for #{get_source(node)}" unless node.respond_to?(direct_child_name)
|
@@ -156,34 +156,34 @@ class NodeMutation::PrismAdapter < NodeMutation::Adapter
|
|
156
156
|
|
157
157
|
if child_node.is_a?(Prism::Node)
|
158
158
|
return(
|
159
|
-
NodeMutation::Struct::Range.new(child_node.location.
|
159
|
+
NodeMutation::Struct::Range.new(child_node.location.start_character_offset, child_node.location.end_character_offset)
|
160
160
|
)
|
161
161
|
end
|
162
162
|
|
163
163
|
return(
|
164
|
-
NodeMutation::Struct::Range.new(child_node.first.location.
|
164
|
+
NodeMutation::Struct::Range.new(child_node.first.location.start_character_offset, child_node.last.location.end_character_offset)
|
165
165
|
)
|
166
166
|
end
|
167
167
|
end
|
168
168
|
|
169
169
|
def get_start(node, child_name = nil)
|
170
170
|
node = child_node_by_name(node, child_name) if child_name
|
171
|
-
node.location.
|
171
|
+
node.location.start_character_offset
|
172
172
|
end
|
173
173
|
|
174
174
|
def get_end(node, child_name = nil)
|
175
175
|
node = child_node_by_name(node, child_name) if child_name
|
176
|
-
node.location.
|
176
|
+
node.location.end_character_offset
|
177
177
|
end
|
178
178
|
|
179
179
|
def get_start_loc(node, child_name = nil)
|
180
180
|
node = child_node_by_name(node, child_name) if child_name
|
181
|
-
NodeMutation::Struct::Location.new(node.location.start_line, node.location.
|
181
|
+
NodeMutation::Struct::Location.new(node.location.start_line, node.location.start_character_column)
|
182
182
|
end
|
183
183
|
|
184
184
|
def get_end_loc(node, child_name = nil)
|
185
185
|
node = child_node_by_name(node, child_name) if child_name
|
186
|
-
NodeMutation::Struct::Location.new(node.location.end_line, node.location.
|
186
|
+
NodeMutation::Struct::Location.new(node.location.end_line, node.location.end_character_column)
|
187
187
|
end
|
188
188
|
|
189
189
|
private
|
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.24.
|
4
|
+
version: 1.24.4
|
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-04-
|
11
|
+
date: 2024-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: ast node mutation apis
|
14
14
|
email:
|