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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a1838915f4699a2c9bc566d05d38ed23f892b31a0a44d3812f4fe54b760a213f
4
- data.tar.gz: 0fc0b9aac1857fc18675578da657a663786eb5ffcb43b2b2f4c27a013487eb78
3
+ metadata.gz: 5fbc8f86a01844e6cefbdc699124dfaef0fa8da5581a4375a4f99132efdc0bbf
4
+ data.tar.gz: 8868c51bced5f0ec6a4dfb52951989ba7dc1e5fad389c9be2d3d96303346e490
5
5
  SHA512:
6
- metadata.gz: 699e09b43684f17ad6d0ab0b3902cc2910eb5ba53a870a5a2dfb6bb1c19b5df770a747c8d8c4e22fb8414cfac7f25acb1e3498465f0f8279abc458544eb4d8b5
7
- data.tar.gz: 3702e772e0379b37d1adea9b7024ebeafe2ea0e77a8b5263a1d9a32b62d581be58e64d1a735d6ac0b7b6bbc3440cfbd477744d03e68da58f5b426fd5209c470b
6
+ metadata.gz: 808c1a596e88980cdbdaab4c8c6fda0e7d21431f4bbb2529a79c1cddaa4fe51f09eadba2ed5a90e6f8f8c8d3c4fd1396a906a4f0cc8398bbf497b35068204390
7
+ data.tar.gz: 6999f0fb1490422a929d9faa2de9daec7ada538fd17c27b6f6f5c19655068a08a5ed87c07a8aec49ab5ef8440353c914d4fc38136087af4cb1601384df4745ff
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # NodeMutation
2
2
 
3
+ ## 1.24.4 (2024-04-16)
4
+
5
+ * Use Prism `character_offset` instead byte `offset`
6
+
3
7
  ## 1.24.3 (2024-04-07)
4
8
 
5
9
  * Update `prism_ext` to 0.3.0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- node_mutation (1.24.3)
4
+ node_mutation (1.24.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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 [ParserAdapter](https://synvert-hq.github.io/node-mutation-ruby/NodeMutation/ParserAdapter.html) and [SyntaxTreeAdapter](https://synvert-hq.github.io/node-mutation-ruby/NodeMutation/SyntaxTreeAdapter.html)
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 ripper, will generate different AST nodes, to make NodeMutation work for them all,
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.start_offset...node.last.location.end_offset]
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.start_offset, child_node.location.end_offset)
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.start_offset, child_node.location.end_offset)
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.start_offset, node_loc.end_offset) if 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.start_offset, node.message_loc.end_offset)
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.start_offset, node.location.end_offset)
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.start_offset, child_node.location.end_offset)
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.start_offset, child_node.last.location.end_offset)
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.start_offset
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.end_offset
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.start_column)
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.end_column)
186
+ NodeMutation::Struct::Location.new(node.location.end_line, node.location.end_character_column)
187
187
  end
188
188
 
189
189
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class NodeMutation
4
- VERSION = "1.24.3"
4
+ VERSION = "1.24.4"
5
5
  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.24.3
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-07 00:00:00.000000000 Z
11
+ date: 2024-04-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: ast node mutation apis
14
14
  email: