node_mutation 1.17.0 → 1.18.0

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: 7df63f45429db131b4023d42d1fcab4fdac401358376f0d2ed16722627484bf0
4
- data.tar.gz: a9fdadb2c0dd0d82cd709040b2c154b4e2bd75b95ca71082e00e5768e15f476a
3
+ metadata.gz: ed3138d259ca0498f5435e750d23f868f85284ff5fd7150a01faef49d191e30c
4
+ data.tar.gz: e4ab22239669f8712a5dda6cd6d01a37f01ec73bb86a9e4429d3b01355b2594b
5
5
  SHA512:
6
- metadata.gz: 7e6194b0d8d80e3b8e553e06c287663a4595bd259f91dbdc9c469c83f4fbabe0781b1ef959fb57341e4d5499993444f21c7fd09283b22f67908495c770446bb2
7
- data.tar.gz: 5b99e2f025960eb624f9b82a40a37a1befc63e4787a8cc3a3cd2067e378e9d4b9dfe5f71f7cee2ec922a7171658704a29e0ff799a16389c62b5f27307e818327
6
+ metadata.gz: c534ac19b76e03a74e2f75eb66754e080e2453dc00f67ddc300b35e097a02577a573a926474d5f6e4ddededa14c434bf18f500f1f16a9591c1a05ce41271338c
7
+ data.tar.gz: f1a49e7ce258e4b4b89f1f3fbf7741fd83b04ede95e5593a1b2e3e57fd2ac5967c2500450a3244b5951435f447d81a01fff01179a53c0242f431b8758e4f97a2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # NodeMutation
2
2
 
3
+ ## 1.18.0 (2023-05-16)
4
+
5
+ * Rename `file_content` to `file_source`
6
+ * Add `SyntaxTreeAdapter#file_source`
7
+
8
+ ## 1.17.1 (2023-05-16)
9
+
10
+ * Require `parser` and `syntax_tree` in adapter
11
+
3
12
  ## 1.17.0 (2023-05-15)
4
13
 
5
14
  * Add `SyntaxTreeAdapter`
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- node_mutation (1.17.0)
4
+ node_mutation (1.18.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -108,6 +108,6 @@ class NodeMutation::Action
108
108
  #
109
109
  # @return [String]
110
110
  def file_source
111
- @file_source ||= NodeMutation.adapter.file_content(@node)
111
+ @file_source ||= NodeMutation.adapter.file_source(@node)
112
112
  end
113
113
  end
@@ -1,11 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'parser'
4
+ require 'parser_node_ext'
5
+
3
6
  class NodeMutation::ParserAdapter < NodeMutation::Adapter
4
7
  def get_source(node)
5
8
  if node.is_a?(Array)
6
9
  return "" if node.empty?
7
10
 
8
- source = file_content(node.first)
11
+ source = file_source(node.first)
9
12
  source[node.first.loc.expression.begin_pos...node.last.loc.expression.end_pos]
10
13
  else
11
14
  node.loc.expression.source
@@ -25,7 +28,7 @@ class NodeMutation::ParserAdapter < NodeMutation::Adapter
25
28
  end
26
29
  when Array
27
30
  if evaluated.size > 0
28
- file_source = file_content(evaluated.first)
31
+ file_source = file_source(evaluated.first)
29
32
  source = file_source[evaluated.first.loc.expression.begin_pos...evaluated.last.loc.expression.end_pos]
30
33
  lines = source.split "\n"
31
34
  lines_count = lines.length
@@ -49,7 +52,7 @@ class NodeMutation::ParserAdapter < NodeMutation::Adapter
49
52
  end
50
53
  end
51
54
 
52
- def file_content(node)
55
+ def file_source(node)
53
56
  node.loc.expression.source_buffer.source
54
57
  end
55
58
 
@@ -159,7 +162,7 @@ class NodeMutation::ParserAdapter < NodeMutation::Adapter
159
162
  end
160
163
 
161
164
  def get_indent(node)
162
- file_content(node).split("\n")[get_start_loc(node).line - 1][/\A */].size
165
+ file_source(node).split("\n")[get_start_loc(node).line - 1][/\A */].size
163
166
  end
164
167
 
165
168
  private
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'syntax_tree'
4
+ require 'syntax_tree_ext'
5
+
3
6
  class NodeMutation::SyntaxTreeAdapter < NodeMutation::Adapter
4
7
  def get_source(node)
5
8
  if node.is_a?(Array)
@@ -41,6 +44,10 @@ class NodeMutation::SyntaxTreeAdapter < NodeMutation::Adapter
41
44
  end
42
45
  end
43
46
 
47
+ def file_source(node)
48
+ node.source
49
+ end
50
+
44
51
  def child_node_range(node, child_name)
45
52
  child_node = child_node_by_name(node, child_name)
46
53
  return nil if child_node.nil?
@@ -23,8 +23,8 @@ class NodeMutation::Adapter
23
23
  # The file content of the ast node file
24
24
  # @param node [Node] ast node
25
25
  # @return file content
26
- def file_content(node)
27
- raise NotImplementedError, "file_content is not implemented"
26
+ def file_source(node)
27
+ raise NotImplementedError, "file_source is not implemented"
28
28
  end
29
29
 
30
30
  # Get the start/end range of the child node
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class NodeMutation
4
- VERSION = "1.17.0"
4
+ VERSION = "1.18.0"
5
5
  end
@@ -3,7 +3,7 @@ class NodeMutation::Adapter[T]
3
3
 
4
4
  def rewritten_source: (node: T, code: String) -> String
5
5
 
6
- def file_content: (node: T) -> String
6
+ def file_source: (node: T) -> String
7
7
 
8
8
  def child_node_range: (node: T, child_name: String) -> NodeMutation::Struct::Range
9
9
 
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.17.0
4
+ version: 1.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-05-15 00:00:00.000000000 Z
11
+ date: 2023-05-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: ast node mutation apis
14
14
  email: