node_query 1.13.1 → 1.13.3

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: 9f0ea7e92fbee3e2c0c28554dd021b1e2a07fd4c64b9dd7f1a6b5acbc7d8385f
4
- data.tar.gz: cc317efc39dd07bc30c1cd54cd03eded67c82a92a37b809340add4c8372e77ea
3
+ metadata.gz: '09b566f97aa10b9630187ef0dee3b703480eb01347a44d799295c8a8d1111dcd'
4
+ data.tar.gz: a68b6f479e49aad2bf8dd7e3e03d4a53f0e7fe3c21dd77d7b9ac5adee3c1408b
5
5
  SHA512:
6
- metadata.gz: b7bb08d7bacc6da4232f7e16a9397e565ae4b4523b8d177068672441aecdcaa49a01be8b3e614aeef138e365ad210bd1e121857690061324f889e8486105c79a
7
- data.tar.gz: 2736927c6b34ee327b02e4230bc4b8879f8582f8a9840740c99bd122a9d53eecd5c099dc2e3b2407629047a88e3477e253d878fe56e835264e38a405ede78bc2
6
+ metadata.gz: c8eefe2252d378dceaae5dc878c3383e6c48004888440e0a7b87c93a70c168ba6ed102c84adac60426b922727d455270f23f95abc88d21a008f4aa6527e01315
7
+ data.tar.gz: 5996c60bd2df1bec0660b2468924a77f50b06e53d7206d09caaa723e3b06d82dab1ffc4133bdc0fe46c3e521a5c278b24f0cd9e584ae12e01ff05896a512aa21
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.13.3 (2023-06-14)
4
+
5
+ * Use `deconstruct_key` to get syntax_tree node children
6
+ * `handle_recursive_child` handles Array child node
7
+
8
+ ## 1.13.2 (2023-05-18)
9
+
10
+ * Replace `Parser` specific code
11
+
3
12
  ## 1.13.1 (2023-05-16)
4
13
 
5
14
  * Require `parser` and `syntax_tree` in adapter
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- node_query (1.13.1)
4
+ node_query (1.13.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -67,7 +67,7 @@ GEM
67
67
  shellany (0.0.1)
68
68
  syntax_tree (6.1.1)
69
69
  prettier_print (>= 1.2.0)
70
- syntax_tree_ext (0.3.0)
70
+ syntax_tree_ext (0.3.1)
71
71
  syntax_tree
72
72
  thor (1.2.1)
73
73
 
@@ -13,11 +13,11 @@ class NodeQuery::SyntaxTreeAdapter
13
13
  end
14
14
 
15
15
  def get_source(node)
16
- node.source
16
+ node.to_source
17
17
  end
18
18
 
19
19
  def get_children(node)
20
- node.child_nodes
20
+ node.deconstruct_keys([]).except(:location, :comments).values
21
21
  end
22
22
 
23
23
  def get_siblings(node)
@@ -90,22 +90,7 @@ module NodeQuery::Compiler
90
90
  # @return the node value, could be integer, float, string, boolean, nil, range, and etc.
91
91
  def actual_value(node)
92
92
  if NodeQuery.adapter.is_node?(node)
93
- case NodeQuery.adapter.get_node_type(node)
94
- when :int, :float, :str, :sym
95
- NodeQuery.adapter.get_children(node).last
96
- when :true
97
- true
98
- when :false
99
- false
100
- when :nil
101
- nil
102
- when :array
103
- NodeQuery.adapter.get_children(node).map { |child_node| actual_value(child_node) }
104
- when :begin
105
- actual_value(NodeQuery.adapter.get_children(node).first)
106
- else
107
- node
108
- end
93
+ node.to_value
109
94
  else
110
95
  node
111
96
  end
@@ -31,8 +31,8 @@ module NodeQuery::Compiler
31
31
  end
32
32
 
33
33
  # Check if node matches the selector.
34
- # @param node [Parser::AST::Node] the node
35
- # @param base_node [Parser::AST::Node] the base node for evaluated node
34
+ # @param node [Node] the node
35
+ # @param base_node [Node] the base node for evaluated node
36
36
  def match?(node, base_node, operator = "==")
37
37
  if node.is_a?(::Array)
38
38
  case operator
@@ -153,9 +153,9 @@ module NodeQuery::Compiler
153
153
  nodes << child_node if @rest.match?(child_node, child_node)
154
154
  end
155
155
  else
156
- node.children.each do |child_node|
156
+ NodeQuery.adapter.get_children(node).each do |child_node|
157
157
  if NodeQuery.adapter.is_node?(child_node) && :begin == NodeQuery.adapter.get_node_type(child_node)
158
- child_node.children.each do |child_child_node|
158
+ NodeQuery.adapter.get_children(child_node).each do |child_child_node|
159
159
  nodes << child_child_node if @rest.match?(child_child_node, child_child_node)
160
160
  end
161
161
  elsif @rest.match?(child_node, child_node)
@@ -30,12 +30,17 @@ class NodeQuery::Helper
30
30
  # Recursively handle child nodes.
31
31
  # @param node [Node] ast node
32
32
  # @yield [child] Gives a child node.
33
- # @yieldparam child [Parser::AST::Node] child node
33
+ # @yieldparam child [Node] child node
34
34
  def handle_recursive_child(node, &block)
35
35
  NodeQuery.adapter.get_children(node).each do |child|
36
36
  if NodeQuery.adapter.is_node?(child)
37
37
  block.call(child)
38
38
  handle_recursive_child(child, &block)
39
+ elsif child.is_a?(Array)
40
+ child.each do |child_child|
41
+ block.call(child_child)
42
+ handle_recursive_child(child_child, &block)
43
+ end
39
44
  end
40
45
  end
41
46
  end
@@ -95,14 +95,14 @@ class NodeQuery::NodeRules
95
95
 
96
96
  case expected
97
97
  when Symbol
98
- if actual.is_a?(Parser::AST::Node)
98
+ if NodeQuery.adapter.is_node?(actual)
99
99
  actual_source = NodeQuery.adapter.get_source(actual)
100
100
  actual_source == ":#{expected}" || actual_source == expected.to_s
101
101
  else
102
102
  actual.to_sym == expected
103
103
  end
104
104
  when String
105
- if actual.is_a?(Parser::AST::Node)
105
+ if NodeQuery.adapter.is_node?(actual)
106
106
  actual_source = NodeQuery.adapter.get_source(actual)
107
107
  actual_source == expected || actual_source == unwrap_quote(expected) ||
108
108
  unwrap_quote(actual_source) == expected || unwrap_quote(actual_source) == unwrap_quote(expected)
@@ -110,7 +110,7 @@ class NodeQuery::NodeRules
110
110
  actual.to_s == expected || wrap_quote(actual.to_s) == expected
111
111
  end
112
112
  when Regexp
113
- if actual.is_a?(Parser::AST::Node)
113
+ if NodeQuery.adapter.is_node?(actual)
114
114
  actual.to_source =~ Regexp.new(expected.to_s, Regexp::MULTILINE)
115
115
  else
116
116
  actual.to_s =~ Regexp.new(expected.to_s, Regexp::MULTILINE)
@@ -120,13 +120,13 @@ class NodeQuery::NodeRules
120
120
 
121
121
  actual.zip(expected).all? { |a, e| match_value?(a, e) }
122
122
  when NilClass
123
- if actual.is_a?(Parser::AST::Node)
123
+ if NodeQuery.adapter.is_node?(actual)
124
124
  :nil == actual.type
125
125
  else
126
126
  actual.nil?
127
127
  end
128
128
  when Numeric
129
- if actual.is_a?(Parser::AST::Node)
129
+ if NodeQuery.adapter.is_node?(actual)
130
130
  actual.children[0] == expected
131
131
  else
132
132
  actual == expected
@@ -135,10 +135,12 @@ class NodeQuery::NodeRules
135
135
  :true == actual&.type
136
136
  when FalseClass
137
137
  :false == actual&.type
138
- when Parser::AST::Node
139
- actual == expected
140
138
  else
141
- raise NodeQuery::MethodNotSupported, "#{expected} is not supported"
139
+ if NodeQuery.adapter.is_node?(expected)
140
+ actual == expected
141
+ else
142
+ raise NodeQuery::MethodNotSupported, "#{expected} is not supported"
143
+ end
142
144
  end
143
145
  end
144
146
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class NodeQuery
4
- VERSION = "1.13.1"
4
+ VERSION = "1.13.3"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: node_query
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.13.1
4
+ version: 1.13.3
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-15 00:00:00.000000000 Z
11
+ date: 2023-06-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: ast node query language
14
14
  email:
@@ -78,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
78
  - !ruby/object:Gem::Version
79
79
  version: '0'
80
80
  requirements: []
81
- rubygems_version: 3.4.10
81
+ rubygems_version: 3.4.13
82
82
  signing_key:
83
83
  specification_version: 4
84
84
  summary: ast node query language