ruby-next-core 0.7.0 → 0.8.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: 293ae08c0e4ae536624da190361e2825a5b17ee9c0589626540c05ff87e6ef0a
4
- data.tar.gz: 45da1dcbc37d0c87c7f47cb300c38540dcd04085d8a85298747ca27e1c1ae99f
3
+ metadata.gz: bb8a0798576c2859d40a9bcc7ce9b4c5a9bcdd2560a603bdf14b897a1248edc2
4
+ data.tar.gz: 38f599eb8a725bb52ad7a7ae66342c3450da6906366a8d6e53304484ca60a1b5
5
5
  SHA512:
6
- metadata.gz: 2e93d7c73f2d90cdc5005c62d85aef1c55fdc05fc8ae333a05749518e0a61e4d6317d378d9df39ed5e4afc8ee2c6853f3fac714ad6751a7204c75f9a0754e244
7
- data.tar.gz: '053942e5c78cac2092a36491dc36d54e1f83aaa9a91dc4ecc021dfdc9c8c62572a549c063d1df70d618094694c1f8c4d13b69d3a50727551184a3bc5a38c40be'
6
+ metadata.gz: abdb54f137bce953dfe24eaa29dcb35c057534821ac2dbd5a4b3092608aa88b6a2e8ac81032f86766d2eda29c70bbc0b2acd79f72dcd2490d230cd92a34af00b
7
+ data.tar.gz: ff4087bb6b6ecf1cc159166b0a4a8bcc650d2ef1ee315f3eeee5e8b8b1f3005ce560c4fcd7ffd5673cef206fbaf7f3fca2e0f0a594fda042b5f5178d43ea2a5b
@@ -2,6 +2,18 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 0.8.0 (2020-05-01) 🚩
6
+
7
+ - Add right-hand assignment support. ([@palkan][])
8
+
9
+ It is real: `13.divmod(5) => a, b`.
10
+
11
+ - Add endless methods support. ([@palkan][])
12
+
13
+ Now you can write `def foo() = :bar`.
14
+
15
+ ## 0.7.0 (2020-04-29)
16
+
5
17
  - Try to auto-transpile the source code on load in `.setup_gem_load_path` if transpiled files are missing. ([@palkan][])
6
18
 
7
19
  This would make it possible to install gems from source if transpiled files do not exist in the repository.
data/README.md CHANGED
@@ -62,12 +62,16 @@ $ gem install ruby-next
62
62
 
63
63
  # Call ruby with -ruby-next flag
64
64
  $ ruby -ruby-next -e "
65
- case {hello: 'martian'}
66
- in hello: hello if hello =~ /human/
67
- puts '🙂'
68
- in hello: 'martian'
69
- puts '👽'
70
- end
65
+ def greet(val) =
66
+ case val
67
+ in hello: hello if hello =~ /human/i
68
+ '🙂'
69
+ in hello: 'martian'
70
+ '👽'
71
+ end
72
+
73
+ greet(hello: 'martian') => greeting
74
+ puts greeting
71
75
  "
72
76
 
73
77
  => 👽
@@ -160,6 +164,8 @@ You can change the transpiler mode:
160
164
  - Via environmental variable `RUBY_NEXT_TRANSPILE_MODE=rewrite`.
161
165
  - Via CLI option ([see below](#cli)).
162
166
 
167
+ **NOTE:** For the time being, Unparser [doesn't support](https://github.com/mbj/unparser/pull/142) new Ruby 2.7 AST nodes, so we always use rewrite mode in Ruby 2.7+.
168
+
163
169
  ## CLI
164
170
 
165
171
  Ruby Next ships with the command-line interface (`ruby-next`) which provides the following functionality:
@@ -431,11 +437,13 @@ require "ruby-next/language/runtime"
431
437
 
432
438
  ### Supported edge features
433
439
 
434
- Not yet.
440
+ - "Endless" method definition (`def foo() = 42`) ([#16746](https://bugs.ruby-lang.org/issues/16746)).
441
+
442
+ - Right-hand assignment (`13.divmod(5) => a,b`) ([#15921](https://bugs.ruby-lang.org/issues/15921))
435
443
 
436
444
  ### Supported proposed features
437
445
 
438
- - _Method reference_ operator (`.:`) ([link](https://bugs.ruby-lang.org/issues/13581)).
446
+ - _Method reference_ operator (`.:`) ([#13581](https://bugs.ruby-lang.org/issues/13581)).
439
447
 
440
448
  ## Contributing
441
449
 
@@ -5,11 +5,10 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
 
6
6
  require "bundler/setup"
7
7
 
8
- require "ruby-next/language"
8
+ ENV["RUBY_NEXT_EDGE"] = "1"
9
+ ENV["RUBY_NEXT_PROPOSED"] = "1"
9
10
 
10
- # optional parsers
11
- require "ruby-next/language/rewriters/method_reference"
12
- RubyNext::Language.rewriters << RubyNext::Language::Rewriters::MethodReference
11
+ require "ruby-next/language"
13
12
 
14
13
  contents =
15
14
  if File.exist?(ARGV[0])
@@ -11,10 +11,10 @@ module RubyNext
11
11
 
12
12
  # Defines last minor version for every major version
13
13
  LAST_MINOR_VERSIONS = {
14
- 2 => 7
14
+ 2 => 8
15
15
  }.freeze
16
16
 
17
- LATEST_VERSION = [2, 7].freeze
17
+ LATEST_VERSION = [2, 8].freeze
18
18
 
19
19
  class << self
20
20
  def next_version(version = RUBY_VERSION)
@@ -97,7 +97,13 @@ module RubyNext
97
97
  rewriters = Language.rewriters.select { |rw| rw.unsupported_version?(version) }
98
98
 
99
99
  context = Language::TransformContext.new
100
- new_contents = Language.transform contents, context: context, rewriters: rewriters
100
+
101
+ new_contents =
102
+ if Gem::Version.new(version) >= Gem::Version.new("2.7.0") && !defined?(Unparser::Emitter::CaseMatch)
103
+ Language.rewrite contents, context: context, rewriters: rewriters
104
+ else
105
+ Language.transform contents, context: context, rewriters: rewriters
106
+ end
101
107
 
102
108
  return unless context.dirty?
103
109
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- gem "ruby-next-parser", ">= 2.8.0.0"
3
+ gem "ruby-next-parser", ">= 2.8.0.3"
4
4
  gem "unparser", ">= 0.4.7"
5
5
 
6
6
  require "set"
@@ -83,6 +83,12 @@ module RubyNext
83
83
  end
84
84
 
85
85
  def runtime!
86
+ if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.7.0") && !defined?(Unparser::Emitter::CaseMatch)
87
+ RubyNext.warn "Ruby Next fallbacks to \"rewrite\" transpiling mode since Unparser doesn't support 2.7 AST yet.\n" \
88
+ "See https://github.com/mbj/unparser/pull/142"
89
+ self.mode = :rewrite
90
+ end
91
+
86
92
  @runtime = true
87
93
  end
88
94
 
@@ -1,3 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Load edge Ruby features
4
+
5
+ require "ruby-next/language/rewriters/endless_method"
6
+ RubyNext::Language.rewriters << RubyNext::Language::Rewriters::EndlessMethod
7
+
8
+ require "ruby-next/language/rewriters/right_hand_assignment"
9
+ RubyNext::Language.rewriters << RubyNext::Language::Rewriters::RightHandAssignment
@@ -25,21 +25,23 @@ module RubyNext
25
25
  end
26
26
 
27
27
  def on_send(node)
28
- return unless node.children[2]&.type == :forwarded_args
28
+ return super(node) unless node.children[2]&.type == :forwarded_args
29
29
 
30
30
  replace(node.children[2].loc.expression, "*#{REST}, &#{BLOCK}")
31
31
 
32
- node.updated(
33
- nil,
34
- [
35
- *node.children[0..1],
36
- *forwarded_args
37
- ]
32
+ process(
33
+ node.updated(
34
+ nil,
35
+ [
36
+ *node.children[0..1],
37
+ *forwarded_args
38
+ ]
39
+ )
38
40
  )
39
41
  end
40
42
 
41
43
  def on_super(node)
42
- return unless node.children[0]&.type == :forwarded_args
44
+ return super(node) unless node.children[0]&.type == :forwarded_args
43
45
 
44
46
  replace(node.children[0].loc.expression, "*#{REST}, &#{BLOCK}")
45
47
 
@@ -78,10 +78,6 @@ module RubyNext
78
78
  def transform(source)
79
79
  Language.transform(source, rewriters: [self], using: false)
80
80
  end
81
-
82
- def warn_custom_parser_required_for(feature)
83
- RubyNext.warn(CUSTOM_PARSER_REQUIRED % feature)
84
- end
85
81
  end
86
82
 
87
83
  attr_reader :locals
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyNext
4
+ module Language
5
+ module Rewriters
6
+ class EndlessMethod < Base
7
+ SYNTAX_PROBE = "obj = Object.new; def obj.foo() = 42"
8
+ MIN_SUPPORTED_VERSION = Gem::Version.new("2.8.0")
9
+
10
+ def on_def_e(node)
11
+ context.track! self
12
+
13
+ replace(node.loc.assignment, "; ")
14
+ insert_after(node.loc.expression, "; end")
15
+
16
+ process(
17
+ node.updated(
18
+ :def,
19
+ node.children
20
+ )
21
+ )
22
+ end
23
+
24
+ def on_defs_e(node)
25
+ context.track! self
26
+
27
+ replace(node.loc.assignment, "; ")
28
+ insert_after(node.loc.expression, "; end")
29
+
30
+ process(
31
+ node.updated(
32
+ :defs,
33
+ node.children
34
+ )
35
+ )
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyNext
4
+ module Language
5
+ module Rewriters
6
+ class RightHandAssignment < Base
7
+ SYNTAX_PROBE = "1 + 2 => a"
8
+ MIN_SUPPORTED_VERSION = Gem::Version.new("2.8.0")
9
+
10
+ def on_rasgn(node)
11
+ context.track! self
12
+
13
+ val_node, asgn_node = *node
14
+
15
+ remove(val_node.loc.expression.end.join(asgn_node.loc.expression))
16
+ insert_before(val_node.loc.expression, "#{asgn_node.loc.expression.source} = ")
17
+
18
+ process(
19
+ asgn_node.updated(
20
+ nil,
21
+ asgn_node.children + [val_node]
22
+ )
23
+ )
24
+ end
25
+
26
+ def on_mrasgn(node)
27
+ context.track! self
28
+
29
+ lhs, rhs = *node
30
+
31
+ replace(lhs.loc.expression.end.join(rhs.loc.expression), ")")
32
+ insert_before(lhs.loc.expression, "#{rhs.loc.expression.source} = (")
33
+
34
+ process(
35
+ node.updated(
36
+ :masgn,
37
+ [rhs, lhs]
38
+ )
39
+ )
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -84,6 +84,32 @@ module RuboCop
84
84
  send(:"on_#{child.type}", child)
85
85
  end
86
86
  end
87
+
88
+ unless method_defined?(:on_def_e)
89
+ def on_def_e(node)
90
+ _name, _args_node, body_node = *node
91
+ send(:"on_#{body_node.type}", body_node)
92
+ end
93
+
94
+ def on_defs_e(node)
95
+ _definee_node, _name, _args_node, body_node = *node
96
+ send(:"on_#{body_node.type}", body_node)
97
+ end
98
+ end
99
+
100
+ unless method_defined?(:on_rasgn)
101
+ def on_rasgn(node)
102
+ val_node, asgn_node = *node
103
+ send(:"on_#{asgn_node.type}", asgn_node)
104
+ send(:"on_#{val_node.type}", val_node)
105
+ end
106
+
107
+ def on_mrasgn(node)
108
+ lhs, rhs = *node
109
+ send(:"on_#{lhs.type}", lhs)
110
+ send(:"on_#{rhs.type}", rhs)
111
+ end
112
+ end
87
113
  end
88
114
  end
89
115
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyNext
4
- VERSION = "0.7.0"
4
+ VERSION = "0.8.0"
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.7.0
4
+ version: 0.8.0
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-04-29 00:00:00.000000000 Z
11
+ date: 2020-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-next-parser
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 2.8.0.0
19
+ version: 2.8.0.4
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 2.8.0.0
26
+ version: 2.8.0.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: unparser
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -90,10 +90,12 @@ files:
90
90
  - lib/ruby-next/language/proposed.rb
91
91
  - lib/ruby-next/language/rewriters/args_forward.rb
92
92
  - lib/ruby-next/language/rewriters/base.rb
93
+ - lib/ruby-next/language/rewriters/endless_method.rb
93
94
  - lib/ruby-next/language/rewriters/endless_range.rb
94
95
  - lib/ruby-next/language/rewriters/method_reference.rb
95
96
  - lib/ruby-next/language/rewriters/numbered_params.rb
96
97
  - lib/ruby-next/language/rewriters/pattern_matching.rb
98
+ - lib/ruby-next/language/rewriters/right_hand_assignment.rb
97
99
  - lib/ruby-next/language/runtime.rb
98
100
  - lib/ruby-next/language/setup.rb
99
101
  - lib/ruby-next/language/unparser.rb