node_mutation 1.24.3 → 1.25.0

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: f74888530f258a368af4e42872e6f686d3a02756a868ff94a8e12e1aea39b431
4
+ data.tar.gz: 28e4adc21338f64d123611d2958da04c78f8b75c40c3620306cb588e335dd730
5
5
  SHA512:
6
- metadata.gz: 699e09b43684f17ad6d0ab0b3902cc2910eb5ba53a870a5a2dfb6bb1c19b5df770a747c8d8c4e22fb8414cfac7f25acb1e3498465f0f8279abc458544eb4d8b5
7
- data.tar.gz: 3702e772e0379b37d1adea9b7024ebeafe2ea0e77a8b5263a1d9a32b62d581be58e64d1a735d6ac0b7b6bbc3440cfbd477744d03e68da58f5b426fd5209c470b
6
+ metadata.gz: b52d006e8587ea14318b48008f2c18a6ad79601307c1f7862eb72931e093c7db36258874236e74ca620ab753786e4c1a93e631f39146501d1143c719cc5f4e45
7
+ data.tar.gz: 8a9021aaa38e7f3f7a7a559e293b931fca19054b8dbe3d07e1502cf4ccb456cd8b9eaedb0415c2d3049c6a6371a0efcc0ae91af6cb6073177882b179c7ae539c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # NodeMutation
2
2
 
3
+ ## 1.25.0 (2025-12-30)
4
+
5
+ * Support ruby 4.0
6
+ * Drop support ruby 2.7, 3.0, 3.1
7
+
8
+ ## 1.24.4 (2024-04-16)
9
+
10
+ * Use Prism `character_offset` instead byte `offset`
11
+
3
12
  ## 1.24.3 (2024-04-07)
4
13
 
5
14
  * Update `prism_ext` to 0.3.0
data/Gemfile CHANGED
@@ -5,6 +5,8 @@ source "https://rubygems.org"
5
5
  # Specify your gem's dependencies in node_mutation.gemspec
6
6
  gemspec
7
7
 
8
+ gem "ostruct", "~> 0.6"
9
+
8
10
  gem "rake", "~> 13.0"
9
11
 
10
12
  gem "rspec", "~> 3.0"
data/Gemfile.lock CHANGED
@@ -1,12 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- node_mutation (1.24.3)
4
+ node_mutation (1.25.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- ast (2.4.2)
9
+ ast (2.4.3)
10
10
  coderay (1.1.3)
11
11
  diff-lcs (1.5.0)
12
12
  ffi (1.15.5)
@@ -34,19 +34,20 @@ GEM
34
34
  notiffany (0.1.3)
35
35
  nenv (~> 0.1)
36
36
  shellany (~> 0.0)
37
- parser (3.3.0.5)
37
+ ostruct (0.6.3)
38
+ parser (3.3.10.0)
38
39
  ast (~> 2.4.1)
39
40
  racc
40
- parser_node_ext (1.3.0)
41
+ parser_node_ext (1.4.2)
41
42
  parser
42
43
  prettier_print (1.2.1)
43
- prism (0.25.0)
44
- prism_ext (0.3.0)
44
+ prism (1.7.0)
45
+ prism_ext (0.4.2)
45
46
  prism
46
47
  pry (0.14.1)
47
48
  coderay (~> 1.1)
48
49
  method_source (~> 1.0)
49
- racc (1.7.3)
50
+ racc (1.8.1)
50
51
  rake (13.0.6)
51
52
  rb-fsevent (0.11.1)
52
53
  rb-inotify (0.10.1)
@@ -65,13 +66,15 @@ GEM
65
66
  rspec-support (~> 3.11.0)
66
67
  rspec-support (3.11.0)
67
68
  shellany (0.0.1)
68
- syntax_tree (6.2.0)
69
+ syntax_tree (6.3.0)
69
70
  prettier_print (>= 1.2.0)
70
- syntax_tree_ext (0.8.1)
71
+ syntax_tree_ext (0.9.2)
71
72
  syntax_tree
72
73
  thor (1.2.1)
73
74
 
74
75
  PLATFORMS
76
+ arm64-darwin-24
77
+ arm64-darwin-25
75
78
  x86_64-darwin-21
76
79
  x86_64-darwin-22
77
80
  x86_64-darwin-23
@@ -81,6 +84,7 @@ DEPENDENCIES
81
84
  guard
82
85
  guard-rspec
83
86
  node_mutation!
87
+ ostruct (~> 0.6)
84
88
  parser_node_ext
85
89
  prism_ext
86
90
  rake (~> 13.0)
@@ -88,4 +92,4 @@ DEPENDENCIES
88
92
  syntax_tree_ext
89
93
 
90
94
  BUNDLED WITH
91
- 2.3.7
95
+ 2.6.9
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.25.0"
5
5
  end
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.summary = "ast node mutation apis"
12
12
  spec.description = "ast node mutation apis"
13
13
  spec.homepage = "https://github.com/synvert-hq/node-mutation-ruby"
14
- spec.required_ruby_version = ">= 2.6.0"
14
+ spec.required_ruby_version = ">= 2.7.0"
15
15
 
16
16
  spec.metadata["homepage_uri"] = spec.homepage
17
17
  spec.metadata["source_code_uri"] = "https://github.com/synvert-hq/node-mutation-ruby"
metadata CHANGED
@@ -1,14 +1,13 @@
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.25.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-04-07 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies: []
13
12
  description: ast node mutation apis
14
13
  email:
@@ -59,7 +58,6 @@ metadata:
59
58
  homepage_uri: https://github.com/synvert-hq/node-mutation-ruby
60
59
  source_code_uri: https://github.com/synvert-hq/node-mutation-ruby
61
60
  changelog_uri: https://github.com/synvert-hq/node-mutation-ruby/blob/master/CHANGELOG.md
62
- post_install_message:
63
61
  rdoc_options: []
64
62
  require_paths:
65
63
  - lib
@@ -67,15 +65,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
67
65
  requirements:
68
66
  - - ">="
69
67
  - !ruby/object:Gem::Version
70
- version: 2.6.0
68
+ version: 2.7.0
71
69
  required_rubygems_version: !ruby/object:Gem::Requirement
72
70
  requirements:
73
71
  - - ">="
74
72
  - !ruby/object:Gem::Version
75
73
  version: '0'
76
74
  requirements: []
77
- rubygems_version: 3.5.3
78
- signing_key:
75
+ rubygems_version: 3.6.9
79
76
  specification_version: 4
80
77
  summary: ast node mutation apis
81
78
  test_files: []