node_mutation 1.12.2 → 1.13.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: cf57adfc552f6b661bf4c08a35976f017dc7439c914cb1e419e656952d77bcef
4
- data.tar.gz: ee142c7f5b1b8e2ae7a0b51a36dd8718232918c2fa57595e84470e284fe86411
3
+ metadata.gz: 4d8929809b3553b4b57c7f79ad54c83e3084da686b477ff082c18c43a2950042
4
+ data.tar.gz: bd72ffdee180460d73eda354fc1435b9c55f2c0156625264fd437a7f164912e7
5
5
  SHA512:
6
- metadata.gz: 6a4106b2a6324eac65cb782cb3e3863b4544f7798bb87313205bb5b0cf62d55fc3ed75feb36161fe4810ca5ae030f26bb66347d5b1779a035123a5cddaff12b3
7
- data.tar.gz: fa65851e47d51b26ca21efc76d4b16ebc1d3743e7dae9d616ba696dc2491e600077b934aea8f3c8db5345c9220ddbf7a883461058d0c73e381f1e5ef99f589db
6
+ metadata.gz: 0ada057b589f14d161050ad80cdba1080c70e1102f041cd65e0a6f180cbb34d5e6a462d7d70abe41983da644b3853a46e7389f8adff14e5ae57f2e177bcbf551
7
+ data.tar.gz: '038bb2377ffcce14069cfcaccfe2a6d6d28728c80cef80d2e7c46da0e6d93f28f9c39dd0b3f690d7df1488962ad40f2ffe57d18018c5c115017e008757df6905'
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # NodeMutation
2
2
 
3
+ ## 1.13.0 (2023-03-31)
4
+
5
+ * Adapter `get_start` and `get_end` can parse child node
6
+ * Adapter `get_start_loc` and `get_end_loc` can parse child node
7
+
8
+ ## 1.12.3 (2023-03-30)
9
+
10
+ * `remove_whitespace` for both before and after whitespace
11
+
3
12
  ## 1.12.2 (2023-03-25)
4
13
 
5
14
  * `remove_whitespace` handles more cases
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- node_mutation (1.12.2)
4
+ node_mutation (1.13.0)
5
5
  erubis
6
6
 
7
7
  GEM
@@ -57,12 +57,18 @@ class NodeMutation::Action
57
57
  # e.g. `%i[foo bar]`, if we remove `foo`, the whitespace should also be removed,
58
58
  # the code should be changed to `%i[bar]`.
59
59
  def remove_whitespace
60
+ if file_source[@end] == ' ' && file_source[@start - 1] == ' '
61
+ @start -= 1
62
+ @end += 1
63
+ return
64
+ end
65
+
60
66
  if ["\n", ';', ')', ']', '}', '|', nil].include?(file_source[@end]) && file_source[@start - 1] == ' '
61
67
  @start -= 1
62
68
  return
63
69
  end
64
70
 
65
- if [' ', '(', '[', '{', '|'].include?(file_source[@start - 1]) && file_source[@end] == ' '
71
+ if ['(', '[', '{', '|'].include?(file_source[@start - 1]) && file_source[@end] == ' '
66
72
  @end += 1
67
73
  end
68
74
  end
@@ -35,29 +35,33 @@ class NodeMutation::Adapter
35
35
 
36
36
  # Get start position of ast node
37
37
  # @param node [Node] ast node
38
- # @return [Number] start position
39
- def get_start(node)
38
+ # @param child_name [String] child name selector
39
+ # @return [Number] start position of node or child node
40
+ def get_start(node, child_name = nil)
40
41
  raise NotImplementedError, "get_start is not implemented"
41
42
  end
42
43
 
43
44
  # Get end position of ast node
44
45
  # @param node [Node] ast node
45
- # @return [Number] end position
46
- def get_end(node)
46
+ # @param child_name [String] child name selector
47
+ # @return [Number] end position of node or child node
48
+ def get_end(node, child_name = nil)
47
49
  raise NotImplementedError, "get_end is not implemented"
48
50
  end
49
51
 
50
52
  # Get start location of ast node
51
53
  # @param node [Node] ast node
52
- # @return [{ line: Number, column: Number }] start location
53
- def get_start_loc(node)
54
+ # @param child_name [String] child name selector
55
+ # @return [{ line: Number, column: Number }] start location of node or child node
56
+ def get_start_loc(node, child_name = nil)
54
57
  raise NotImplementedError, "get_start_loc is not implemented"
55
58
  end
56
59
 
57
60
  # Get end location of ast node
58
61
  # @param node [Node] ast node
59
- # @return [{ line: Number, column: Number }] end location
60
- def get_end_loc(node)
62
+ # @param child_name [String] child name selector
63
+ # @return [{ line: Number, column: Number }] end location of node or child node
64
+ def get_end_loc(node, child_name = nil)
61
65
  raise NotImplementedError, "get_end_loc is not implemented"
62
66
  end
63
67
 
@@ -145,20 +145,24 @@ class NodeMutation::ParserAdapter < NodeMutation::Adapter
145
145
  end
146
146
  end
147
147
 
148
- def get_start(node)
148
+ def get_start(node, child_name = nil)
149
+ node = child_node_by_name(node, child_name) if child_name
149
150
  node.loc.expression.begin_pos
150
151
  end
151
152
 
152
- def get_end(node)
153
+ def get_end(node, child_name = nil)
154
+ node = child_node_by_name(node, child_name) if child_name
153
155
  node.loc.expression.end_pos
154
156
  end
155
157
 
156
- def get_start_loc(node)
158
+ def get_start_loc(node, child_name = nil)
159
+ node = child_node_by_name(node, child_name) if child_name
157
160
  begin_loc = node.loc.expression.begin
158
161
  NodeMutation::Struct::Location.new(begin_loc.line, begin_loc.column)
159
162
  end
160
163
 
161
- def get_end_loc(node)
164
+ def get_end_loc(node, child_name = nil)
165
+ node = child_node_by_name(node, child_name) if child_name
162
166
  end_loc = node.loc.expression.end
163
167
  NodeMutation::Struct::Location.new(end_loc.line, end_loc.column)
164
168
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class NodeMutation
4
- VERSION = "1.12.2"
4
+ VERSION = "1.13.0"
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.12.2
4
+ version: 1.13.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-03-25 00:00:00.000000000 Z
11
+ date: 2023-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erubis