ruby-next-core 0.10.1 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +31 -1
  3. data/README.md +12 -14
  4. data/bin/reparse +19 -0
  5. data/bin/transform +22 -8
  6. data/lib/.rbnext/2.3/ruby-next/commands/nextify.rb +5 -2
  7. data/lib/.rbnext/2.3/ruby-next/language/eval.rb +4 -4
  8. data/lib/.rbnext/2.3/ruby-next/language/rewriters/base.rb +25 -10
  9. data/lib/.rbnext/2.3/ruby-next/language/rewriters/endless_range.rb +1 -1
  10. data/lib/.rbnext/2.3/ruby-next/language/rewriters/pattern_matching.rb +133 -103
  11. data/lib/.rbnext/2.3/ruby-next/utils.rb +1 -1
  12. data/lib/.rbnext/2.7/ruby-next/core.rb +203 -0
  13. data/lib/ruby-next.rb +5 -38
  14. data/lib/ruby-next/commands/nextify.rb +4 -1
  15. data/lib/ruby-next/config.rb +45 -0
  16. data/lib/ruby-next/core.rb +5 -4
  17. data/lib/ruby-next/core/array/deconstruct.rb +1 -1
  18. data/lib/ruby-next/core/constants/no_matching_pattern_error.rb +1 -1
  19. data/lib/ruby-next/core/hash/deconstruct_keys.rb +1 -1
  20. data/lib/ruby-next/core/struct/deconstruct_keys.rb +3 -3
  21. data/lib/ruby-next/core_ext.rb +2 -0
  22. data/lib/ruby-next/language.rb +16 -5
  23. data/lib/ruby-next/language/bootsnap.rb +1 -1
  24. data/lib/ruby-next/language/edge.rb +0 -6
  25. data/lib/ruby-next/language/eval.rb +3 -3
  26. data/lib/ruby-next/language/parser.rb +19 -0
  27. data/lib/ruby-next/language/rewriters/args_forward.rb +8 -4
  28. data/lib/ruby-next/language/rewriters/args_forward_leading.rb +75 -0
  29. data/lib/ruby-next/language/rewriters/base.rb +21 -6
  30. data/lib/ruby-next/language/rewriters/in_pattern.rb +56 -0
  31. data/lib/ruby-next/language/rewriters/numbered_params.rb +6 -2
  32. data/lib/ruby-next/language/rewriters/pattern_matching.rb +131 -101
  33. data/lib/ruby-next/language/rewriters/safe_navigation.rb +30 -26
  34. data/lib/ruby-next/language/setup.rb +6 -3
  35. data/lib/ruby-next/language/unparser.rb +10 -0
  36. data/lib/ruby-next/rubocop.rb +79 -12
  37. data/lib/ruby-next/setup_self.rb +2 -2
  38. data/lib/ruby-next/version.rb +1 -1
  39. metadata +15 -6
  40. data/lib/.rbnext/2.3/ruby-next/language/rewriters/right_hand_assignment.rb +0 -107
  41. data/lib/ruby-next/language/rewriters/right_hand_assignment.rb +0 -107
@@ -1,107 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RubyNext
4
- module Language
5
- module Rewriters
6
- class RightHandAssignment < Base
7
- NAME = "right-hand-assignment"
8
- SYNTAX_PROBE = "1 + 2 => a"
9
- MIN_SUPPORTED_VERSION = Gem::Version.new("3.0.0")
10
-
11
- def on_rasgn(node)
12
- context.track! self
13
-
14
- node = super(node)
15
-
16
- val_node, asgn_node = *node
17
-
18
- remove(val_node.loc.expression.end.join(asgn_node.loc.expression))
19
- insert_before(val_node.loc.expression, "#{asgn_node.loc.expression.source} = ")
20
-
21
- asgn_node.updated(
22
- nil,
23
- asgn_node.children + [val_node]
24
- )
25
- end
26
-
27
- def on_vasgn(node)
28
- return super(node) unless rightward?(node)
29
-
30
- context.track! self
31
-
32
- name, val_node = *node
33
-
34
- remove(val_node.loc.expression.end.join(node.loc.name))
35
- insert_before(val_node.loc.expression, "#{name} = ")
36
-
37
- super(node)
38
- end
39
-
40
- def on_casgn(node)
41
- return super(node) unless rightward?(node)
42
-
43
- context.track! self
44
-
45
- scope_node, name, val_node = *node
46
-
47
- if scope_node
48
- scope = scope_node.type == :cbase ? scope_node.loc.expression.source : "#{scope_node.loc.expression.source}::"
49
- name = "#{scope}#{name}"
50
- end
51
-
52
- remove(val_node.loc.expression.end.join(node.loc.name))
53
- insert_before(val_node.loc.expression, "#{name} = ")
54
-
55
- super(node)
56
- end
57
-
58
- def on_mrasgn(node)
59
- context.track! self
60
-
61
- node = super(node)
62
-
63
- lhs, rhs = *node
64
-
65
- replace(lhs.loc.expression.end.join(rhs.loc.expression), ")")
66
- insert_before(lhs.loc.expression, "#{rhs.loc.expression.source} = (")
67
-
68
- node.updated(
69
- :masgn,
70
- [rhs, lhs]
71
- )
72
- end
73
-
74
- def on_masgn(node)
75
- return super(node) unless rightward?(node)
76
-
77
- context.track! self
78
-
79
- rhs, lhs = *node
80
-
81
- replace(lhs.loc.expression.end.join(rhs.loc.expression), ")")
82
- insert_before(lhs.loc.expression, "#{rhs.loc.expression.source} = (")
83
-
84
- super(node)
85
- end
86
-
87
- private
88
-
89
- def rightward?(node)
90
- # Location could be empty for node built by rewriters
91
- return false unless node.loc&.operator
92
-
93
- assignee_loc =
94
- if node.type == :masgn
95
- node.children[0].loc.expression
96
- else
97
- node.loc.name
98
- end
99
-
100
- return false unless assignee_loc
101
-
102
- assignee_loc.begin_pos > node.loc.operator.end_pos
103
- end
104
- end
105
- end
106
- end
107
- end