node_mutation 1.24.2 → 1.24.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e38141291fc9206b5a34d9d856225ba5b304427450683b9170ac0969f582016f
4
- data.tar.gz: 3ab62df74ae56d5261cd78455056490297154af85fd6440688b518b68a282930
3
+ metadata.gz: 5fbc8f86a01844e6cefbdc699124dfaef0fa8da5581a4375a4f99132efdc0bbf
4
+ data.tar.gz: 8868c51bced5f0ec6a4dfb52951989ba7dc1e5fad389c9be2d3d96303346e490
5
5
  SHA512:
6
- metadata.gz: 1d359ca7f5d28d861b9c2a55a7d0ab682e0714a2f180b5b868567ffb363b2d8510891d77fc0e13cbb620d35ffba2aa1a240fd06164f7bc1d8e4f547c72c99ea9
7
- data.tar.gz: 0d393b320a055d06483bfcada65b198176114de94cf946d783c4ab554c83f4dfa220717fc9978d84b0d5f0c6bc1db8dd6e07c11a829b07697e8e94b72f7b81a6
6
+ metadata.gz: 808c1a596e88980cdbdaab4c8c6fda0e7d21431f4bbb2529a79c1cddaa4fe51f09eadba2ed5a90e6f8f8c8d3c4fd1396a906a4f0cc8398bbf497b35068204390
7
+ data.tar.gz: 6999f0fb1490422a929d9faa2de9daec7ada538fd17c27b6f6f5c19655068a08a5ed87c07a8aec49ab5ef8440353c914d4fc38136087af4cb1601384df4745ff
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # NodeMutation
2
2
 
3
+ ## 1.24.4 (2024-04-16)
4
+
5
+ * Use Prism `character_offset` instead byte `offset`
6
+
7
+ ## 1.24.3 (2024-04-07)
8
+
9
+ * Update `prism_ext` to 0.3.0
10
+ * Update `syntax_tree_ext` to 0.8.1
11
+ * Update `parser_node_ext` to 1.3.0
12
+
3
13
  ## 1.24.2 (2024-03-26)
4
14
 
5
15
  * `child_node_range` supports `casgn` `name`
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- node_mutation (1.24.2)
4
+ node_mutation (1.24.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -37,11 +37,11 @@ GEM
37
37
  parser (3.3.0.5)
38
38
  ast (~> 2.4.1)
39
39
  racc
40
- parser_node_ext (1.2.2)
40
+ parser_node_ext (1.3.0)
41
41
  parser
42
42
  prettier_print (1.2.1)
43
- prism (0.24.0)
44
- prism_ext (0.2.3)
43
+ prism (0.25.0)
44
+ prism_ext (0.3.0)
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.7.2)
70
+ syntax_tree_ext (0.8.1)
71
71
  syntax_tree
72
72
  thor (1.2.1)
73
73
 
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # NodeMutation
2
2
 
3
+ [![Build Status](https://github.com/synvert-hq/node-mutation-ruby/actions/workflows/main.yml/badge.svg)](https://github.com/synvert-hq/node-mutation-ruby/actions/workflows/main.yml)
4
+ [![Gem Version](https://img.shields.io/gem/v/node_mutation.svg)](https://rubygems.org/gems/node_mutation)
5
+
3
6
  NodeMutation provides a set of APIs to rewrite node source code.
4
7
 
5
8
  ## Installation
@@ -81,16 +84,24 @@ mutation.replace node, '{{arguments.-1.on_value}}', with: ':update'
81
84
  source # after_commit :do_index, on: :update, if: :indexable?
82
85
  ```
83
86
 
84
- See more in [ParserAdapter](https://xinminlabs.github.io/node-mutation-ruby/NodeMutation/ParserAdapter.html) and [SyntaxTreeAdapter](https://xinminlabs.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)
85
90
 
86
91
  ## Configuration
87
92
 
88
93
  ### adapter
89
94
 
90
- Different parsers, like parse and ripper, will generate different AST nodes, to make NodeMutation work for them all,
91
- we define an [Adapter](https://github.com/xinminlabs/node-mutation-ruby/blob/main/lib/node_mutation/adapter.rb) interface,
95
+ Different parsers, like prism, parse and syntax_tree, will generate different AST nodes, to make NodeMutation work for them all,
96
+ we define an [Adapter](https://github.com/synvert-hq/node-mutation-ruby/blob/main/lib/node_mutation/adapter.rb) interface,
92
97
  if you implement the Adapter interface, you can set it as NodeMutation's adapter.
93
98
 
99
+ It provides 3 adapters
100
+
101
+ 1. `PrismAdapter`
102
+ 2. `ParserAdapter`
103
+ 3. `SyntaxTreeAdapter`
104
+
94
105
  ### strategy
95
106
 
96
107
  It provides 3 strategies to handle conflicts when processing actions:
@@ -116,4 +127,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
116
127
 
117
128
  ## Contributing
118
129
 
119
- Bug reports and pull requests are welcome on GitHub at https://github.com/xinminlabs/node_mutation.
130
+ Bug reports and pull requests are welcome on GitHub at https://github.com/synvert-hq/node_mutation.
@@ -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.2"
4
+ VERSION = "1.24.4"
5
5
  end
@@ -10,12 +10,12 @@ Gem::Specification.new do |spec|
10
10
 
11
11
  spec.summary = "ast node mutation apis"
12
12
  spec.description = "ast node mutation apis"
13
- spec.homepage = "https://github.com/xinminlabs/node-mutation-ruby"
13
+ spec.homepage = "https://github.com/synvert-hq/node-mutation-ruby"
14
14
  spec.required_ruby_version = ">= 2.6.0"
15
15
 
16
16
  spec.metadata["homepage_uri"] = spec.homepage
17
- spec.metadata["source_code_uri"] = "https://github.com/xinminlabs/node-mutation-ruby"
18
- spec.metadata["changelog_uri"] = "https://github.com/xinminlabs/node-mutation-ruby/blob/master/CHANGELOG.md"
17
+ spec.metadata["source_code_uri"] = "https://github.com/synvert-hq/node-mutation-ruby"
18
+ spec.metadata["changelog_uri"] = "https://github.com/synvert-hq/node-mutation-ruby/blob/master/CHANGELOG.md"
19
19
 
20
20
  # Specify which files should be added to the gem when it is released.
21
21
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
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.2
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-03-26 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:
@@ -53,12 +53,12 @@ files:
53
53
  - sig/node_mutation/result.rbs
54
54
  - sig/node_mutation/strategy.rbs
55
55
  - sig/node_mutation/struct.rbs
56
- homepage: https://github.com/xinminlabs/node-mutation-ruby
56
+ homepage: https://github.com/synvert-hq/node-mutation-ruby
57
57
  licenses: []
58
58
  metadata:
59
- homepage_uri: https://github.com/xinminlabs/node-mutation-ruby
60
- source_code_uri: https://github.com/xinminlabs/node-mutation-ruby
61
- changelog_uri: https://github.com/xinminlabs/node-mutation-ruby/blob/master/CHANGELOG.md
59
+ homepage_uri: https://github.com/synvert-hq/node-mutation-ruby
60
+ source_code_uri: https://github.com/synvert-hq/node-mutation-ruby
61
+ changelog_uri: https://github.com/synvert-hq/node-mutation-ruby/blob/master/CHANGELOG.md
62
62
  post_install_message:
63
63
  rdoc_options: []
64
64
  require_paths: