ruby-next-core 0.13.3 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +44 -0
  3. data/README.md +65 -5
  4. data/bin/transform +5 -1
  5. data/lib/.rbnext/2.1/ruby-next/core.rb +7 -1
  6. data/lib/.rbnext/2.1/ruby-next/language.rb +44 -23
  7. data/lib/.rbnext/2.3/ruby-next/commands/nextify.rb +15 -2
  8. data/lib/.rbnext/2.3/ruby-next/language/eval.rb +1 -0
  9. data/lib/.rbnext/2.3/ruby-next/language/rewriters/{endless_range.rb → 2.6/endless_range.rb} +0 -0
  10. data/lib/.rbnext/2.3/ruby-next/language/rewriters/{pattern_matching.rb → 2.7/pattern_matching.rb} +121 -34
  11. data/lib/.rbnext/2.3/ruby-next/language/rewriters/3.1/anonymous_block.rb +68 -0
  12. data/lib/.rbnext/2.3/ruby-next/language/rewriters/base.rb +14 -2
  13. data/lib/.rbnext/2.7/ruby-next/core.rb +7 -1
  14. data/lib/.rbnext/2.7/ruby-next/language/rewriters/2.7/pattern_matching.rb +1061 -0
  15. data/lib/ruby-next/commands/nextify.rb +15 -2
  16. data/lib/ruby-next/config.rb +2 -2
  17. data/lib/ruby-next/core/enumerable/compact.rb +22 -0
  18. data/lib/ruby-next/core/integer/try_convert.rb +16 -0
  19. data/lib/ruby-next/core/matchdata/match.rb +9 -0
  20. data/lib/ruby-next/core/refinement/import.rb +60 -0
  21. data/lib/ruby-next/core.rb +7 -1
  22. data/lib/ruby-next/irb.rb +24 -0
  23. data/lib/ruby-next/language/eval.rb +1 -0
  24. data/lib/ruby-next/language/rewriters/{numeric_literals.rb → 2.1/numeric_literals.rb} +0 -0
  25. data/lib/ruby-next/language/rewriters/{required_kwargs.rb → 2.1/required_kwargs.rb} +0 -0
  26. data/lib/ruby-next/language/rewriters/{safe_navigation.rb → 2.3/safe_navigation.rb} +0 -0
  27. data/lib/ruby-next/language/rewriters/{squiggly_heredoc.rb → 2.3/squiggly_heredoc.rb} +0 -0
  28. data/lib/ruby-next/language/rewriters/{runtime → 2.4}/dir.rb +0 -0
  29. data/lib/ruby-next/language/rewriters/2.5/rescue_within_block.rb +39 -0
  30. data/lib/ruby-next/language/rewriters/{endless_range.rb → 2.6/endless_range.rb} +0 -0
  31. data/lib/ruby-next/language/rewriters/{args_forward.rb → 2.7/args_forward.rb} +0 -0
  32. data/lib/ruby-next/language/rewriters/{numbered_params.rb → 2.7/numbered_params.rb} +0 -0
  33. data/lib/ruby-next/language/rewriters/{pattern_matching.rb → 2.7/pattern_matching.rb} +121 -34
  34. data/lib/ruby-next/language/rewriters/{args_forward_leading.rb → 3.0/args_forward_leading.rb} +0 -0
  35. data/lib/ruby-next/language/rewriters/{endless_method.rb → 3.0/endless_method.rb} +15 -12
  36. data/lib/ruby-next/language/rewriters/{find_pattern.rb → 3.0/find_pattern.rb} +1 -3
  37. data/lib/ruby-next/language/rewriters/3.0/in_pattern.rb +22 -0
  38. data/lib/ruby-next/language/rewriters/3.1/anonymous_block.rb +68 -0
  39. data/lib/ruby-next/language/rewriters/3.1/endless_method_command.rb +46 -0
  40. data/lib/ruby-next/language/rewriters/3.1/oneline_pattern_parensless.rb +41 -0
  41. data/lib/ruby-next/language/rewriters/3.1/pin_vars_pattern.rb +50 -0
  42. data/lib/ruby-next/language/rewriters/3.1/refinement_import_methods.rb +60 -0
  43. data/lib/ruby-next/language/rewriters/{shorthand_hash.rb → 3.1/shorthand_hash.rb} +6 -4
  44. data/lib/ruby-next/language/rewriters/base.rb +14 -2
  45. data/lib/ruby-next/language/{edge.rb → rewriters/edge.rb} +0 -0
  46. data/lib/ruby-next/language/rewriters/proposed/bind_vars_pattern.rb +50 -0
  47. data/lib/ruby-next/language/rewriters/{method_reference.rb → proposed/method_reference.rb} +0 -0
  48. data/lib/ruby-next/language/rewriters/proposed.rb +9 -0
  49. data/lib/ruby-next/language/rewriters/runtime.rb +1 -2
  50. data/lib/ruby-next/language/setup.rb +1 -1
  51. data/lib/ruby-next/language.rb +44 -23
  52. data/lib/ruby-next/pry.rb +90 -0
  53. data/lib/ruby-next/rubocop.rb +24 -4
  54. data/lib/ruby-next/version.rb +1 -1
  55. data/lib/uby-next/irb.rb +3 -0
  56. data/lib/uby-next/pry.rb +3 -0
  57. metadata +40 -43
  58. data/lib/ruby-next/language/proposed.rb +0 -9
  59. data/lib/ruby-next/language/rewriters/in_pattern.rb +0 -56
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyNext
4
+ module Language
5
+ module Rewriters
6
+ class AnonymousBlock < Base
7
+ NAME = "anonymous-block"
8
+ SYNTAX_PROBE = "obj = Object.new; def obj.foo(&) bar(&); end"
9
+ MIN_SUPPORTED_VERSION = Gem::Version.new("3.1.0")
10
+
11
+ BLOCK = :__block__
12
+
13
+ def on_args(node)
14
+ block = node.children.last
15
+
16
+ return super unless ((((__safe_lvar__ = block) || true) && (!__safe_lvar__.nil? || nil)) && __safe_lvar__.type) == :blockarg
17
+ return super unless block.children.first.nil?
18
+
19
+ context.track! self
20
+
21
+ replace(block.loc.expression, "&#{BLOCK}")
22
+
23
+ node.updated(
24
+ :args,
25
+ [
26
+ *node.children.slice(0, node.children.index(block)),
27
+ s(:blockarg, BLOCK)
28
+ ]
29
+ )
30
+ end
31
+
32
+ def on_send(node)
33
+ block = extract_block_pass(node)
34
+ return super unless ((((__safe_lvar__ = block) || true) && (!__safe_lvar__.nil? || nil)) && __safe_lvar__.children) == [nil]
35
+
36
+ process_block(node, block)
37
+ end
38
+
39
+ def on_super(node)
40
+ block = extract_block_pass(node)
41
+ return super unless ((((__safe_lvar__ = block) || true) && (!__safe_lvar__.nil? || nil)) && __safe_lvar__.children) == [nil]
42
+
43
+ process_block(node, block)
44
+ end
45
+
46
+ private
47
+
48
+ def extract_block_pass(node)
49
+ node.children.find { |child| child.is_a?(::Parser::AST::Node) && child.type == :block_pass }
50
+ end
51
+
52
+ def process_block(node, block)
53
+ replace(block.loc.expression, "&#{BLOCK}")
54
+
55
+ process(
56
+ node.updated(
57
+ nil,
58
+ [
59
+ *node.children.take(node.children.index(block)),
60
+ s(:block_pass, s(:lvar, BLOCK))
61
+ ]
62
+ )
63
+ )
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -14,6 +14,18 @@ module RubyNext
14
14
 
15
15
  class Base < ::Parser::TreeRewriter
16
16
  class LocalsTracker
17
+ using(Module.new do
18
+ refine ::Parser::AST::Node do
19
+ def to_index
20
+ ((((__safe_lvar__ = children) || true) && (!__safe_lvar__.nil? || nil)) && __safe_lvar__.first) || type
21
+ end
22
+ end
23
+
24
+ refine ::Object do
25
+ alias to_index itself
26
+ end
27
+ end)
28
+
17
29
  attr_reader :stacks
18
30
 
19
31
  def initialize
@@ -28,7 +40,7 @@ module RubyNext
28
40
  def [](name, suffix = nil)
29
41
  fetch(name).then do |name|
30
42
  next name unless suffix
31
- :"#{name}#{suffix}__"
43
+ :"#{name}#{suffix.to_index}__"
32
44
  end
33
45
  end
34
46
 
@@ -53,7 +65,7 @@ module RubyNext
53
65
  end
54
66
 
55
67
  class << self
56
- # Returns true if the syntax is supported
68
+ # Returns true if the syntax is not supported
57
69
  # by the current Ruby (performs syntax check, not version check)
58
70
  def unsupported_syntax?
59
71
  save_verbose, $VERBOSE = $VERBOSE, nil
@@ -62,7 +62,7 @@ module RubyNext
62
62
  mod_name = singleton? ? singleton.name : mod.name
63
63
  camelized_method_name = method_name.to_s.split("_").map(&:capitalize).join
64
64
 
65
- "#{mod_name}#{camelized_method_name}".gsub(/\W/, "")
65
+ "#{mod_name}#{camelized_method_name}".gsub(/\W/, "") # rubocop:disable Performance/StringReplacement
66
66
  end
67
67
 
68
68
  def build_location(trace_locations)
@@ -173,6 +173,8 @@ require "ruby-next/core/unboundmethod/bind_call"
173
173
  require "ruby-next/core/time/floor"
174
174
  require "ruby-next/core/time/ceil"
175
175
 
176
+ require "ruby-next/core/refinement/import"
177
+
176
178
  # Core extensions required for pattern matching
177
179
  # Required for pattern matching with refinements
178
180
  unless defined?(NoMatchingPatternError)
@@ -191,6 +193,10 @@ require "ruby-next/core/hash/except"
191
193
 
192
194
  require "ruby-next/core/array/intersect"
193
195
 
196
+ require "ruby-next/core/matchdata/match"
197
+ require "ruby-next/core/enumerable/compact"
198
+ require "ruby-next/core/integer/try_convert"
199
+
194
200
  # Generate refinements
195
201
  RubyNext.module_eval do
196
202
  RubyNext::Core.patches.refined.each do |mod, patches|