node_query 1.15.0 → 1.15.1

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: 9215c4354d5f17a61bd0703869547d2dc4eca4b074c5e689451034073c9554da
4
- data.tar.gz: d602ad70ae5d1d8c53ea7192a1c401cbe67450ece27523fa4040e520e9b85558
3
+ metadata.gz: 9b7a968afbfc580614cb1647fd59933e29ca42a51f16bd94d83bfdd2ff6d76f3
4
+ data.tar.gz: a58361e9a486604fd35e5645528ddb3ad1bf49f314ed704e57954678dfac9d78
5
5
  SHA512:
6
- metadata.gz: 4edce7905bb8b5835d0024f80d2e6a34e01602040c67250873e34d3ebd9c2396df5175608ffe1995048c36f681627b3570571a4f293fd35c9d93da76bb33c0aa
7
- data.tar.gz: 9d812e03d9045f344a00a950dbc503ae185cb469844d3f62b98cb3db64659786552e9e46d2209ef809f6a189eae55b98c1a16bf9c2106d12f75519a24dc75d7f
6
+ metadata.gz: 2468e0e6e5fc5b2fe8d9f93e9169394552991a6813af79428d14d6740b206a4f8e4b1eb37c8b7bbea826daf96157bd571d57ac0afdb302b0271ea2be8ffe088c
7
+ data.tar.gz: feecda8504d3b2477a3152b2993cd8b18a301d9f2e07f09e523b2a4cbed8791369ddffcf3c727dd5b059b34cf52aeec83b507451d14c9f4129aef177552022aa
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.15.1 (2024-02-16)
4
+
5
+ * Use `deconstruct_keys` to get prism children
6
+ * Get `PrismAdapter`
7
+ * Read prism node type
8
+
3
9
  ## 1.15.0 (2024-02-10)
4
10
 
5
11
  * Support `prism`
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- node_query (1.15.0)
4
+ node_query (1.15.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -9,7 +9,7 @@ class NodeQuery::PrismAdapter
9
9
  end
10
10
 
11
11
  def get_node_type(node)
12
- node.class.name.split('::').last.to_sym
12
+ node.type
13
13
  end
14
14
 
15
15
  def get_source(node)
@@ -17,11 +17,29 @@ class NodeQuery::PrismAdapter
17
17
  end
18
18
 
19
19
  def get_children(node)
20
- node.child_nodes
20
+ keys = []
21
+ children = []
22
+ node.deconstruct_keys([]).each do |key, value|
23
+ next if [:flags, :location].include?(key)
24
+
25
+ if key.to_s.end_with?('_loc')
26
+ new_key = key.to_s[0..-5]
27
+ unless keys.include?(new_key)
28
+ keys << new_key
29
+ children << node.send(new_key)
30
+ end
31
+ else
32
+ unless keys.include?(key.to_s)
33
+ keys << key.to_s
34
+ children << value
35
+ end
36
+ end
37
+ end
38
+ children
21
39
  end
22
40
 
23
41
  def get_siblings(node)
24
- child_nodes = node.parent_node.child_nodes
42
+ child_nodes = get_children(node.parent_node)
25
43
  if child_nodes.is_a?(Array) && child_nodes.size == 1 && child_nodes.first.is_a?(Array)
26
44
  index = child_nodes.first.index(node)
27
45
  return child_nodes.first[index + 1...]
@@ -3,14 +3,6 @@
3
3
  require 'syntax_tree'
4
4
  require 'syntax_tree_ext'
5
5
 
6
- if RUBY_VERSION.to_i < 3
7
- class Hash
8
- def except(*keys)
9
- self.reject { |k, _| keys.include?(k) }
10
- end
11
- end
12
- end
13
-
14
6
  class NodeQuery::SyntaxTreeAdapter
15
7
  def is_node?(node)
16
8
  node.is_a?(SyntaxTree::Node)
@@ -25,7 +17,8 @@ class NodeQuery::SyntaxTreeAdapter
25
17
  end
26
18
 
27
19
  def get_children(node)
28
- node.deconstruct_keys([]).except(:location, :comments).values
20
+ node.deconstruct_keys([]).filter { |key, _value| ![:location, :comments].include?(key) }
21
+ .values
29
22
  end
30
23
 
31
24
  def get_siblings(node)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class NodeQuery
4
- VERSION = "1.15.0"
4
+ VERSION = "1.15.1"
5
5
  end
data/lib/node_query.rb CHANGED
@@ -66,6 +66,8 @@ class NodeQuery
66
66
  ParserAdapter.new
67
67
  when :syntax_tree
68
68
  SyntaxTreeAdapter.new
69
+ when :prism
70
+ PrismAdapter.new
69
71
  else
70
72
  raise InvalidAdapterError, "adapter #{adapter} is not supported"
71
73
  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.15.0
4
+ version: 1.15.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-02-10 00:00:00.000000000 Z
11
+ date: 2024-02-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: ast node query language
14
14
  email: