node_mutation 1.18.0 → 1.18.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: ed3138d259ca0498f5435e750d23f868f85284ff5fd7150a01faef49d191e30c
4
- data.tar.gz: e4ab22239669f8712a5dda6cd6d01a37f01ec73bb86a9e4429d3b01355b2594b
3
+ metadata.gz: 66c10f74e41d63887a03af240cdfe99086395505ef43e14dab21f9d7ece562ac
4
+ data.tar.gz: 73728f0f84e095b7f97b65511cbd75fc01bcb7b8e9f2a56965dda31bfb7da622
5
5
  SHA512:
6
- metadata.gz: c534ac19b76e03a74e2f75eb66754e080e2453dc00f67ddc300b35e097a02577a573a926474d5f6e4ddededa14c434bf18f500f1f16a9591c1a05ce41271338c
7
- data.tar.gz: f1a49e7ce258e4b4b89f1f3fbf7741fd83b04ede95e5593a1b2e3e57fd2ac5967c2500450a3244b5951435f447d81a01fff01179a53c0242f431b8758e4f97a2
6
+ metadata.gz: 030fff9b3477f6c8f35454f01cf24f430b1bcabd9f2002c97ebb6f7579db777432e3cddd40bb2c188bcedfab408c255b8aa554a03410df375b51e0ad498d6240
7
+ data.tar.gz: 34078dd910cacc649c23334d13dea818d728cef40d7b130325b204bfb34ec46a07691bb98c94c6223c5d40cf808db1e83002473907ca94dededc661652b0bf85
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # NodeMutation
2
2
 
3
+ ## 1.18.2 (2023-05-21)
4
+
5
+ * Use `rindex` to calculate "do" index
6
+
7
+ ## 1.18.1 (2023-05-20)
8
+
9
+ * Support block/class/def/defs/module `body` in `child_node_range`
10
+ * Return nil if `arguments` is empty in `child_node_range`
11
+
3
12
  ## 1.18.0 (2023-05-16)
4
13
 
5
14
  * Rename `file_content` to `file_source`
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- node_mutation (1.18.0)
4
+ node_mutation (1.18.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -9,14 +9,12 @@ class NodeMutation::PrependAction < NodeMutation::Action
9
9
 
10
10
  private
11
11
 
12
- DO_LENGTH = ' do'.length
13
-
14
12
  # Calculate the begin and end positions.
15
13
  def calculate_position
16
14
  node_start = NodeMutation.adapter.get_start(@node)
17
15
  node_source = NodeMutation.adapter.get_source(@node)
18
16
  first_line = node_source.split("\n").first
19
- @start = first_line.end_with?("do") ? node_start + first_line.index("do") + "do".length : node_start + first_line.length
17
+ @start = first_line.end_with?("do") ? node_start + first_line.rindex("do") + "do".length : node_start + first_line.length
20
18
  @end = @start
21
19
  end
22
20
 
@@ -80,15 +80,32 @@ class NodeMutation::ParserAdapter < NodeMutation::Adapter
80
80
 
81
81
  case [node.type, child_name.to_sym]
82
82
  when %i[block pipes], %i[def parentheses], %i[defs parentheses]
83
- NodeMutation::Struct::Range.new(
84
- node.arguments.first.loc.expression.begin_pos - 1,
85
- node.arguments.last.loc.expression.end_pos + 1
86
- )
83
+ if node.arguments.empty?
84
+ nil
85
+ else
86
+ NodeMutation::Struct::Range.new(
87
+ node.arguments.first.loc.expression.begin_pos - 1,
88
+ node.arguments.last.loc.expression.end_pos + 1
89
+ )
90
+ end
87
91
  when %i[block arguments], %i[def arguments], %i[defs arguments]
88
- NodeMutation::Struct::Range.new(
89
- node.arguments.first.loc.expression.begin_pos,
90
- node.arguments.last.loc.expression.end_pos
91
- )
92
+ if node.arguments.empty?
93
+ nil
94
+ else
95
+ NodeMutation::Struct::Range.new(
96
+ node.arguments.first.loc.expression.begin_pos,
97
+ node.arguments.last.loc.expression.end_pos
98
+ )
99
+ end
100
+ when %i[block body], %i[class body], %i[def body], %i[defs body], %i[module body]
101
+ if node.body.empty?
102
+ nil
103
+ else
104
+ NodeMutation::Struct::Range.new(
105
+ node.body.first.loc.expression.begin_pos,
106
+ node.body.last.loc.expression.end_pos
107
+ )
108
+ end
92
109
  when %i[class name], %i[const name], %i[cvar name], %i[def name], %i[defs name], %i[gvar name], %i[ivar name], %i[lvar name]
93
110
  NodeMutation::Struct::Range.new(node.loc.name.begin_pos, node.loc.name.end_pos)
94
111
  when %i[const double_colon]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class NodeMutation
4
- VERSION = "1.18.0"
4
+ VERSION = "1.18.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.18.0
4
+ version: 1.18.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: 2023-05-16 00:00:00.000000000 Z
11
+ date: 2023-05-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: ast node mutation apis
14
14
  email: