ruby-next-core 0.10.0 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6cab7345f16f61d3a35a307024885c4b9a0055bb946f473bdd5a386b27175ec2
4
- data.tar.gz: c3b2004bf5cd1b9dd49d2a7892bd3e88472a632f4cdc8da310bdb56fb96171d9
3
+ metadata.gz: b97da767efae69a9faa9ed2b4c4a3daf9c38a5b70768502b013692b7a3c04a50
4
+ data.tar.gz: 05ba2f4c4677c40d46a451a68a94e434b54d4e9daa9a2af51cbd508ef0a198ab
5
5
  SHA512:
6
- metadata.gz: 4f6b3d6f64e0303e1b69fa5a99ececcf605c7413285c05feb03d9308da8449296fbea96b8779a3ac6b72dca8351ac10cd20f11161b1581ac6a60a85d951ca0d3
7
- data.tar.gz: 44e5f05020cae47e13d1a89627c94d890b07daccd1e7dcf51e2e4e0eed208fca2c946e4db674f53fa0581477a368e80c73474ffc657a53f55c1e962bd3d668ba
6
+ metadata.gz: ef678d9b8ed431a8a8f005b00c445da56096c39a3c9ffc1ce88708c4b1280e630cb5c58a63a154381c384b54968ec19b3c88a4a49665b3503bd5df62f454a168
7
+ data.tar.gz: a25ebf4e0c3456213a1f682d27df031a6add5bc117800026d8b0f9b48cacb49e72a4b97115f9b1b1acf058ca3f6974dfa94402498a58a19ac532916eb9a81199
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 0.10.1 (2020-09-09)
6
+
7
+ - Fix regression when `nextify` produces incorrect files for 2.7. ([@palkan][])
8
+
5
9
  ## 0.10.0 (2020-09-02)
6
10
 
7
11
  - Add proposed shorthand Hash syntax. ([@palkan][])
@@ -72,6 +72,10 @@ module RubyNext
72
72
  self::MIN_SUPPORTED_VERSION > version
73
73
  end
74
74
 
75
+ def min_supported_minor_version
76
+ Gem::Version.new(self::MIN_SUPPORTED_VERSION.segments[0..1].join(".") + ".0")
77
+ end
78
+
75
79
  private
76
80
 
77
81
  def transform(source)
@@ -0,0 +1,107 @@
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.nil?) || nil) && 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
@@ -39,7 +39,7 @@ module RubyNext
39
39
  # Called by rewriter when it performs transfomrations
40
40
  def track!(rewriter)
41
41
  @dirty = true
42
- versions << rewriter.class::MIN_SUPPORTED_VERSION
42
+ versions << rewriter.class.min_supported_minor_version
43
43
  end
44
44
 
45
45
  def use_ruby_next!
@@ -73,6 +73,10 @@ module RubyNext
73
73
  self::MIN_SUPPORTED_VERSION > version
74
74
  end
75
75
 
76
+ def min_supported_minor_version
77
+ Gem::Version.new(self::MIN_SUPPORTED_VERSION.segments[0..1].join(".") + ".0")
78
+ end
79
+
76
80
  private
77
81
 
78
82
  def transform(source)
@@ -11,34 +11,96 @@ module RubyNext
11
11
  def on_rasgn(node)
12
12
  context.track! self
13
13
 
14
+ node = super(node)
15
+
14
16
  val_node, asgn_node = *node
15
17
 
16
18
  remove(val_node.loc.expression.end.join(asgn_node.loc.expression))
17
19
  insert_before(val_node.loc.expression, "#{asgn_node.loc.expression.source} = ")
18
20
 
19
- process(
20
- asgn_node.updated(
21
- nil,
22
- asgn_node.children + [val_node]
23
- )
21
+ asgn_node.updated(
22
+ nil,
23
+ asgn_node.children + [val_node]
24
24
  )
25
25
  end
26
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
+
27
58
  def on_mrasgn(node)
28
59
  context.track! self
29
60
 
61
+ node = super(node)
62
+
30
63
  lhs, rhs = *node
31
64
 
32
65
  replace(lhs.loc.expression.end.join(rhs.loc.expression), ")")
33
66
  insert_before(lhs.loc.expression, "#{rhs.loc.expression.source} = (")
34
67
 
35
- process(
36
- node.updated(
37
- :masgn,
38
- [rhs, lhs]
39
- )
68
+ node.updated(
69
+ :masgn,
70
+ [rhs, lhs]
40
71
  )
41
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
42
104
  end
43
105
  end
44
106
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyNext
4
- VERSION = "0.10.0"
4
+ VERSION = "0.10.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-next-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Dementyev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-02 00:00:00.000000000 Z
11
+ date: 2020-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-next-parser
@@ -61,6 +61,7 @@ files:
61
61
  - lib/.rbnext/2.3/ruby-next/language/rewriters/base.rb
62
62
  - lib/.rbnext/2.3/ruby-next/language/rewriters/endless_range.rb
63
63
  - lib/.rbnext/2.3/ruby-next/language/rewriters/pattern_matching.rb
64
+ - lib/.rbnext/2.3/ruby-next/language/rewriters/right_hand_assignment.rb
64
65
  - lib/.rbnext/2.3/ruby-next/utils.rb
65
66
  - lib/ruby-next.rb
66
67
  - lib/ruby-next/cli.rb