node_mutation 1.24.0 → 1.24.2

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: 6083384501299b7550d7a91ddee8a643ebfa8ef1d167dd8b95687af79ddcbad4
4
- data.tar.gz: a1e8ac6f05d36650b5d012a3f5e1bc3adbd7b0a5fde2d2f7eb559bd2a5abea31
3
+ metadata.gz: e38141291fc9206b5a34d9d856225ba5b304427450683b9170ac0969f582016f
4
+ data.tar.gz: 3ab62df74ae56d5261cd78455056490297154af85fd6440688b518b68a282930
5
5
  SHA512:
6
- metadata.gz: 6fa73367b5a8508bb4b7f5c5fc5831c00f3f1e6d36b9eef0b5cb87ea9814514317d61d0ae5c016b35459e1a232de0fc32a3b9f437c62642ac017d1d406e7f9bf
7
- data.tar.gz: 67d8d95f5f3877905b55ef4e5c30e193ed8f20d7f1516e93fd26552a5887eae4d3f29c4da85064f8c09844a6188899eb2af32e812e8f573f1c2d2cdf0c6d4cd4
6
+ metadata.gz: 1d359ca7f5d28d861b9c2a55a7d0ab682e0714a2f180b5b868567ffb363b2d8510891d77fc0e13cbb620d35ffba2aa1a240fd06164f7bc1d8e4f547c72c99ea9
7
+ data.tar.gz: 0d393b320a055d06483bfcada65b198176114de94cf946d783c4ab554c83f4dfa220717fc9978d84b0d5f0c6bc1db8dd6e07c11a829b07697e8e94b72f7b81a6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # NodeMutation
2
2
 
3
+ ## 1.24.2 (2024-03-26)
4
+
5
+ * `child_node_range` supports `casgn` `name`
6
+
7
+ ## 1.24.1 (2024-03-05)
8
+
9
+ * Adjust `start` and `end` position of `AppendAction` and `PrependAction`
10
+
3
11
  ## 1.24.0 (2024-03-03)
4
12
 
5
13
  * Remove `Adapter#get_indent`
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- node_mutation (1.24.0)
4
+ node_mutation (1.24.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -12,13 +12,27 @@ class NodeMutation::AppendAction < NodeMutation::Action
12
12
  @type = :insert
13
13
  end
14
14
 
15
+ # The rewritten source code with proper indent.
16
+ #
17
+ # @return [String] rewritten code.
18
+ def new_code
19
+ if rewritten_source.split("\n").length > 1
20
+ "\n" + rewritten_source.split("\n").map { |line| indent(@node) + line }.join("\n") + "\n"
21
+ else
22
+ indent(@node) + rewritten_source + "\n"
23
+ end
24
+ end
25
+
15
26
  private
16
27
 
17
28
  END_LENGTH = "\nend".length
18
29
 
19
30
  # Calculate the begin the end positions.
20
31
  def calculate_position
21
- @start = @adapter.get_end(@node) - @adapter.get_start_loc(@node).column - END_LENGTH
32
+ node_end = @adapter.get_end(@node)
33
+ node_source = @adapter.get_source(@node)
34
+ last_line = node_source.split("\n").last
35
+ @start = node_end - last_line.length
22
36
  @end = @start
23
37
  end
24
38
 
@@ -12,6 +12,17 @@ class NodeMutation::PrependAction < NodeMutation::Action
12
12
  @type = :insert
13
13
  end
14
14
 
15
+ # The rewritten source code with proper indent.
16
+ #
17
+ # @return [String] rewritten code.
18
+ def new_code
19
+ if rewritten_source.split("\n").length > 1
20
+ "\n" + rewritten_source.split("\n").map { |line| indent(@node) + line }.join("\n") + "\n"
21
+ else
22
+ indent(@node) + rewritten_source + "\n"
23
+ end
24
+ end
25
+
15
26
  private
16
27
 
17
28
  # Calculate the begin and end positions.
@@ -19,7 +30,7 @@ class NodeMutation::PrependAction < NodeMutation::Action
19
30
  node_start = @adapter.get_start(@node)
20
31
  node_source = @adapter.get_source(@node)
21
32
  first_line = node_source.split("\n").first
22
- @start = first_line.end_with?("do") ? node_start + first_line.rindex("do") + "do".length : node_start + first_line.length
33
+ @start = node_start + first_line.length + "\n".length
23
34
  @end = @start
24
35
  end
25
36
 
@@ -31,18 +31,6 @@ class NodeMutation::Action
31
31
  self
32
32
  end
33
33
 
34
- # The rewritten source code with proper indent.
35
- #
36
- # @return [String] rewritten code.
37
- def new_code
38
- if rewritten_source.split("\n").length > 1
39
- "\n\n" + rewritten_source.split("\n").map { |line| indent(@node) + line }
40
- .join("\n")
41
- else
42
- "\n" + indent(@node) + rewritten_source
43
- end
44
- end
45
-
46
34
  def to_struct
47
35
  to_struct_actions = @actions ? @actions.map(&:to_struct) : nil
48
36
  NodeMutation::Struct::Action.new(@type, @start, @end, new_code, to_struct_actions)
@@ -175,7 +175,7 @@ class NodeMutation::ParserAdapter < NodeMutation::Adapter
175
175
  node.arguments.last.loc.expression.end_pos + 1
176
176
  )
177
177
  end
178
- when %i[arg name], %i[class name], %i[const name], %i[cvar name], %i[def name], %i[defs name],
178
+ when %i[arg name], %i[class name], %i[const name], %i[cvar name], %i[casgn name], %i[def name], %i[defs name],
179
179
  %i[gvar name], %i[ivar name], %i[lvar name]
180
180
 
181
181
  NodeMutation::Struct::Range.new(node.loc.name.begin_pos, node.loc.name.end_pos)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class NodeMutation
4
- VERSION = "1.24.0"
4
+ VERSION = "1.24.2"
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.0
4
+ version: 1.24.2
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-03 00:00:00.000000000 Z
11
+ date: 2024-03-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: ast node mutation apis
14
14
  email: