node_mutation 1.19.1 → 1.19.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: 07cffea51271875fe053793222f92ba3ed88fb977e90c875d7f6096b969de898
4
- data.tar.gz: f532736d3c384703dca1cfa389b4cad86fb810d8b063540ad50774af649786c8
3
+ metadata.gz: ec537b5f02531d1a6134c09db1be0d0845226a231da01cbda1e9331103a04fb3
4
+ data.tar.gz: f5cf6c624b25b08de8ea2f82c46401a3ce530c58720fa47cac11f04445c11894
5
5
  SHA512:
6
- metadata.gz: c900a66575d3c35780bf64f33aa3452a5cd558ba7e55cde46f0c322f5da8cf54f17b052683a71df74c51df7efda8e3626e451f987fd1ea5f3995afd3f72635f4
7
- data.tar.gz: f2335ad6e3ad0a5dcd1ec36d0f595c114d703dea847f36d6b1235a4ceb1cc92e6fe27522cd941da0e34e3864ccb9abd169f9f83e02a9306ab6075f8d2ea1c09d
6
+ metadata.gz: 7d491e39ed40c9392c0bd4b1ca47cb2d6078756526b85d2ff5a01b9b5c7ec4cf452fe14c502a1066c878a00d532d88152d026e367b67b8c2de6904577e0c3ef0
7
+ data.tar.gz: d0946badaef12e2bc7701df604d7186174f72cc74d7dc797e38a82f20e05cfd6c07ea6d677c818bc16db583b735f4ae5652c799b7df2d664463977bd524d7b71
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # NodeMutation
2
2
 
3
+ ## 1.19.2 (2023-06-30)
4
+
5
+ * Support `operator` of `Binary` node in `child_node_range`
6
+
3
7
  ## 1.19.1 (2023-06-22)
4
8
 
5
9
  * Add `to_string` function
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- node_mutation (1.19.1)
4
+ node_mutation (1.19.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -62,7 +62,7 @@ GEM
62
62
  shellany (0.0.1)
63
63
  syntax_tree (6.1.1)
64
64
  prettier_print (>= 1.2.0)
65
- syntax_tree_ext (0.3.0)
65
+ syntax_tree_ext (0.6.1)
66
66
  syntax_tree
67
67
  thor (1.2.1)
68
68
 
@@ -102,12 +102,18 @@ class NodeMutation::SyntaxTreeAdapter < NodeMutation::Adapter
102
102
  # @example
103
103
  # node = SyntaxTree::Parser.new('foo.bar(test)').parse.statements.body.first
104
104
  # child_node_range(node, 'receiver') => { start: 0, end: 'foo'.length }
105
- # node array
105
+ #
106
+ # # node array
106
107
  # node = SyntaxTree::Parser.new('foo.bar(a, b)').parse.statements.body.first
107
108
  # child_node_range(node, 'arguments.arguments') => { start: 'foo.bar('.length, end: 'foo.bar(a, b'.length }
108
- # index for node array
109
+ #
110
+ # # index for node array
109
111
  # node = SyntaxTree::Parser.new('foo.bar(a, b)').parse.statements.body.first
110
112
  # child_node_range(node, 'arguments.arguments.parts.-1') => { start: 'foo.bar(a, '.length, end: 'foo.bar(a, b'.length }
113
+ #
114
+ # # operator of Binary node
115
+ # node = SyntaxTree::Parser.new('foo | bar').parse.statements.body.first
116
+ # child_node_range(node, 'operator') => { start: 'foo '.length, end: 'foo |'.length }
111
117
  def child_node_range(node, child_name)
112
118
  child_node = child_node_by_name(node, child_name)
113
119
  return nil if child_node.nil?
@@ -116,6 +122,14 @@ class NodeMutation::SyntaxTreeAdapter < NodeMutation::Adapter
116
122
  return NodeMutation::Struct::Range.new(child_node.first.location.start_char, child_node.last.location.end_char)
117
123
  end
118
124
 
125
+ if node.is_a?(SyntaxTree::Binary) && child_name == 'operator'
126
+ start_char = node.left.location.end_char
127
+ start_char += 1 while node.source[start_char] == ' '
128
+ end_char = node.right.location.start_char
129
+ end_char -= 1 while node.source[end_char - 1] == ' '
130
+ return NodeMutation::Struct::Range.new(start_char, end_char)
131
+ end
132
+
119
133
  return NodeMutation::Struct::Range.new(child_node.location.start_char, child_node.location.end_char)
120
134
  end
121
135
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class NodeMutation
4
- VERSION = "1.19.1"
4
+ VERSION = "1.19.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.19.1
4
+ version: 1.19.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-06-22 00:00:00.000000000 Z
11
+ date: 2023-06-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: ast node mutation apis
14
14
  email: