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 +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +2 -2
- data/lib/node_mutation/adapter/syntax_tree.rb +16 -2
- data/lib/node_mutation/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec537b5f02531d1a6134c09db1be0d0845226a231da01cbda1e9331103a04fb3
|
4
|
+
data.tar.gz: f5cf6c624b25b08de8ea2f82c46401a3ce530c58720fa47cac11f04445c11894
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d491e39ed40c9392c0bd4b1ca47cb2d6078756526b85d2ff5a01b9b5c7ec4cf452fe14c502a1066c878a00d532d88152d026e367b67b8c2de6904577e0c3ef0
|
7
|
+
data.tar.gz: d0946badaef12e2bc7701df604d7186174f72cc74d7dc797e38a82f20e05cfd6c07ea6d677c818bc16db583b735f4ae5652c799b7df2d664463977bd524d7b71
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
node_mutation (1.19.
|
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.
|
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
|
-
#
|
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
|
-
#
|
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
|
|
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.
|
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-
|
11
|
+
date: 2023-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: ast node mutation apis
|
14
14
|
email:
|