parser_node_ext 1.3.1 → 1.4.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: 50a45e7affbc066c77b4b1ced9b3b9e95f44dda27d545406a81835c3272eada5
4
- data.tar.gz: 20b65501f3e92ea387a1a3f28ec67627cd3c6ea48228a7988c309730a68d380d
3
+ metadata.gz: 22a93ba0be1ba11d2ad229213f3d23cdced0a9ddcd7c0bfc7ca5554477309f1a
4
+ data.tar.gz: f7ee7d6199fbf215e4edc131f05bf6f8029e830a4aba46f41d9003fd4dd34639
5
5
  SHA512:
6
- metadata.gz: 69a851d7c5e73797708dd354c5b9f145d6d6c525b234b5be9c2d7c9e79ef690117a1c8c9bdb068a428a0796403d67a91104dd327551c004f42c6168d7e41d92a
7
- data.tar.gz: 660151c08259100c51194e374c8db31ff66fb2acaf76a9f8c41c594029de8ef775f2a4bdc352718860224c31531fca0e63b6cefdb7e85bc1511e1ce26e86a462
6
+ metadata.gz: 6ed6775dcbf7b3da276c8bbaf7d10be7da230d3ad46ea92aa9f25f7b150f4b73fb4b2fe8db0c53f6354db6ff6cb58494817907074dec159152cf54fcbb9a5e17
7
+ data.tar.gz: 625449de48bc393ae3eec749d6a1c3753161deb2224742962b588e6ae128f50f1f0b68619f95e356c89c9f0ac647a68e083eea0334d8bba6e5ac6be2bbbc5c4e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.4.0 (2024-07-16)
4
+
5
+ * require `parser_node_ext/parent_node_ext` back
6
+
7
+ ## 1.3.2 (2024-04-18)
8
+
9
+ * Remove `hash_pair` and `hash_value` methods
10
+
3
11
  ## 1.3.1 (2024-04-18)
4
12
 
5
13
  * Remove `.key?` method
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- parser_node_ext (1.3.1)
4
+ parser_node_ext (1.4.0)
5
5
  parser
6
6
 
7
7
  GEM
@@ -9,10 +9,10 @@ GEM
9
9
  specs:
10
10
  ast (2.4.2)
11
11
  diff-lcs (1.5.0)
12
- parser (3.3.0.5)
12
+ parser (3.3.4.0)
13
13
  ast (~> 2.4.1)
14
14
  racc
15
- racc (1.7.3)
15
+ racc (1.8.0)
16
16
  rake (13.0.6)
17
17
  rspec (3.11.0)
18
18
  rspec-core (~> 3.11.0)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ParserNodeExt
4
- VERSION = "1.3.1"
4
+ VERSION = "1.4.0"
5
5
  end
@@ -3,6 +3,7 @@
3
3
  require_relative "parser_node_ext/version"
4
4
 
5
5
  require 'parser'
6
+ require_relative "parser_node_ext/parent_node_ext"
6
7
 
7
8
  module ParserNodeExt
8
9
  class MethodNotSupported < StandardError; end
@@ -319,37 +320,6 @@ module ParserNodeExt
319
320
  end
320
321
  end
321
322
 
322
- # Get :hash pair node according to specified key.
323
- # @example
324
- # node # s(:hash, s(:pair, s(:sym, :foo), s(:sym, :bar)))
325
- # node.hash_pair(:foo) # s(:pair, s(:sym, :foo), s(:sym, :bar))
326
- # @param [Symbol, String] key value.
327
- # @return [Parser::AST::Node] hash pair node.
328
- # @raise [MethodNotSupported] if calls on other node.
329
- def hash_pair(key)
330
- if %i[hash hash_pattern].include?(type)
331
- pairs.find { |pair_node| pair_node.key.to_value == key }
332
- else
333
- raise MethodNotSupported, "hash_pair is not supported for #{self}"
334
- end
335
- end
336
-
337
- # Get :hash value node according to specified key.
338
- # @example
339
- # node # s(:hash, s(:pair, s(:sym, :foo), s(:sym, :bar)))
340
- # node.hash_value(:foo) # s(:sym, :bar)
341
- # @param [Symbol, String] key value.
342
- # @return [Parser::AST::Node] hash value node.
343
- # @raise [MethodNotSupported] if calls on other node.
344
- def hash_value(key)
345
- if %i[hash hash_pattern].include?(type)
346
- value_node = pairs.find { |pair_node| pair_node.key.to_value == key }
347
- value_node&.value
348
- else
349
- raise MethodNotSupported, "hash_value is not supported for #{self}"
350
- end
351
- end
352
-
353
323
  # Get kwsplats of :hash and :hash_pattern node.
354
324
  # @example
355
325
  # node s(:hash, s(:pair, s(:int, 1), s(:int, 2)), s(:kwsplat, s(:send, nil, :bar)), s(:pair, s(:sym, :baz), s(:int, 3)))
@@ -407,22 +377,13 @@ module ParserNodeExt
407
377
  return children.send(method_name, *args, &block)
408
378
  elsif :hash == type && method_name.to_s.end_with?('_pair')
409
379
  key = method_name.to_s[0..-6]
410
- return hash_pair(key.to_sym) if keys.map(&:to_value).include?(key.to_sym)
411
- return hash_pair(key.to_s) if keys.map(&:to_value).include?(key.to_s)
412
-
413
- return nil
380
+ return pairs.find { |pair| pair.key.to_value.to_s == key }
414
381
  elsif :hash == type && method_name.to_s.end_with?('_value')
415
382
  key = method_name.to_s[0..-7]
416
- return hash_value(key.to_sym) if keys.map(&:to_value).include?(key.to_sym)
417
- return hash_value(key.to_s) if keys.map(&:to_value).include?(key.to_s)
418
-
419
- return nil
383
+ return pairs.find { |pair| pair.key.to_value.to_s == key }&.value
420
384
  elsif :hash == type && method_name.to_s.end_with?('_source')
421
385
  key = method_name.to_s[0..-8]
422
- return hash_value(key.to_sym)&.to_source if keys.map(&:to_value).include?(key.to_sym)
423
- return hash_value(key.to_s)&.to_source if keys.map(&:to_value).include?(key.to_s)
424
-
425
- return ''
386
+ return pairs.find { |pair| pair.key.to_value.to_s == key }&.value&.to_source || ''
426
387
  end
427
388
 
428
389
  super
@@ -433,13 +394,13 @@ module ParserNodeExt
433
394
  return true
434
395
  elsif :hash == type && method_name.to_s.end_with?('_pair')
435
396
  key = method_name.to_s[0..-6]
436
- return keys.map(&:to_value).include?(key.to_sym) || keys.map(&:to_value).include?(key.to_s)
397
+ return !!pairs.find { |pair| pair.key.to_value.to_s == key }
437
398
  elsif :hash == type && method_name.to_s.end_with?('_value')
438
399
  key = method_name.to_s[0..-7]
439
- return keys.map(&:to_value).include?(key.to_sym) || keys.map(&:to_value).include?(key.to_s)
400
+ return !!pairs.find { |pair| pair.key.to_value.to_s == key }
440
401
  elsif :hash == type && method_name.to_s.end_with?('_source')
441
402
  key = method_name.to_s[0..-8]
442
- return keys.map(&:to_value).include?(key.to_sym) || keys.map(&:to_value).include?(key.to_s)
403
+ return !!pairs.find { |pair| pair.key.to_value.to_s == key }
443
404
  end
444
405
 
445
406
  super
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parser_node_ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.4.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: 2024-04-18 00:00:00.000000000 Z
11
+ date: 2024-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -63,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
63
  - !ruby/object:Gem::Version
64
64
  version: '0'
65
65
  requirements: []
66
- rubygems_version: 3.5.3
66
+ rubygems_version: 3.5.14
67
67
  signing_key:
68
68
  specification_version: 4
69
69
  summary: extend parser node