ruby-next-core 0.5.3 → 0.6.0
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 +4 -4
- data/CHANGELOG.md +17 -0
- data/README.md +45 -36
- data/lib/ruby-next/cli.rb +0 -1
- data/lib/ruby-next/commands/nextify.rb +8 -3
- data/lib/ruby-next/language/edge.rb +3 -0
- data/lib/ruby-next/language/parser.rb +2 -2
- data/lib/ruby-next/language/proposed.rb +6 -0
- data/lib/ruby-next/language.rb +7 -4
- data/lib/ruby-next/rubocop.rb +44 -1
- data/lib/ruby-next/version.rb +1 -1
- data/lib/uby-next.rb +4 -0
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5447b309915122d9f6dc9a366c34a566891c9f9cc569722c0999e020ef891d6b
|
4
|
+
data.tar.gz: 9c2da837b1c9e4d2d36ea8665a90f7d3c004d6175b1d0e82262396846ac00f6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7644e4703b233a730a3af183efaae78ea53cf5915ea70cc297ab8ebc8ff9346aad233c642cbf1d38ec82dc49deeab266e20ed35667e6c4069a7bb2f16b6c4e16
|
7
|
+
data.tar.gz: 42fe6bf61bfd0cc97c1107455b873d97065eeb3f8c0c6ae3d7921b1fa208c155114e0e6012045d335fa31f1591093fabb58a3a2f1828c9fe668c2e798335ee80
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,23 @@
|
|
2
2
|
|
3
3
|
## master
|
4
4
|
|
5
|
+
## 0.6.0 (2020-04-23)
|
6
|
+
|
7
|
+
- Changed the way edge/proposed features are activated. ([@palkan][])
|
8
|
+
|
9
|
+
Use `--edge` or `--proposed` flags for `ruby-next nextify` or
|
10
|
+
`require "ruby-next/language/{edge,proposed}"` in your code.
|
11
|
+
|
12
|
+
See more in the [Readme](./README.md#proposed-and-edge-features).
|
13
|
+
|
14
|
+
- Updated RuboCop integration. ([@palkan][])
|
15
|
+
|
16
|
+
Make sure you use `TargetRubyVersion: next` in your RuboCop configuration.
|
17
|
+
|
18
|
+
- Upgraded to `ruby-next-parser` for edge features. ([@palkan][])
|
19
|
+
|
20
|
+
It's no longer needed to use Parser gem from Ruby Next package registry.
|
21
|
+
|
5
22
|
## 0.5.3 (2020-03-25)
|
6
23
|
|
7
24
|
- Enhance logging. ([@palkan][])
|
data/README.md
CHANGED
@@ -27,6 +27,7 @@ That's why Ruby Next implements the `master` features as fast as possible.
|
|
27
27
|
## Table of contents
|
28
28
|
|
29
29
|
- [Overview](#overview)
|
30
|
+
- [Quick Start](#quick-start)
|
30
31
|
- [Polyfills](#using-only-polyfills)
|
31
32
|
- [Transpiling](#transpiling)
|
32
33
|
- [Modes](#transpiler-modes)
|
@@ -51,6 +52,27 @@ programmatically or via CLI. It also could be done in runtime.
|
|
51
52
|
Currently, Ruby Next supports Ruby versions 2.5+ (including JRuby 9.2.8+).
|
52
53
|
Please, [open an issue](https://github.com/ruby-next/ruby-next/issues/new/choose) if you would like us to support older Ruby versions.
|
53
54
|
|
55
|
+
## Quick start
|
56
|
+
|
57
|
+
The quickest way to start experimenting with Ruby Next is to install the gem and run a sample script. For example:
|
58
|
+
|
59
|
+
```sh
|
60
|
+
# Install Ruby Next globally
|
61
|
+
$ gem install ruby-next
|
62
|
+
|
63
|
+
# Call ruby with -ruby-next flag
|
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
|
71
|
+
"
|
72
|
+
|
73
|
+
=> 👽
|
74
|
+
```
|
75
|
+
|
54
76
|
## Using only polyfills
|
55
77
|
|
56
78
|
First, install a gem:
|
@@ -79,7 +101,7 @@ using RubyNext
|
|
79
101
|
|
80
102
|
Ruby Next only refines core classes if necessary; thus, this line wouldn't have any effect in the edge Ruby.
|
81
103
|
|
82
|
-
**NOTE:** Even if the runtime already contains a monkey-patch with the backported functionality, we consider the method as _dirty_ and activate the refinement for it. Thus, you always have
|
104
|
+
**NOTE:** Even if the runtime already contains a monkey-patch with the backported functionality, we consider the method as _dirty_ and activate the refinement for it. Thus, you always have predictable behaviour. That's why we recommend using refinements for gems development.
|
83
105
|
|
84
106
|
Alternatively, you can go with monkey-patches. Just add this line:
|
85
107
|
|
@@ -124,7 +146,7 @@ gem install ruby-next
|
|
124
146
|
|
125
147
|
Ruby Next currently provides two different modes of generating transpiled code: _AST_ and _rewrite_.
|
126
148
|
|
127
|
-
In the AST mode, we parse the source code into AST, modifies this AST and **generate a new code from AST** (using [unparser][unparser]). Thus, the transpiled code being identical in terms of functionality has
|
149
|
+
In the AST mode, we parse the source code into AST, modifies this AST and **generate a new code from AST** (using [unparser][unparser]). Thus, the transpiled code being identical in terms of functionality has different formatting.
|
128
150
|
|
129
151
|
In the rewrite mode, we apply changes to the source code itself, thus, keeping the original formatting of the unaffected code (in a similar way to RuboCop's autocorrect feature).
|
130
152
|
|
@@ -292,10 +314,12 @@ To enable this integration, add the following line after the `require "bootsnap/
|
|
292
314
|
require "ruby-next/language/bootsnap"
|
293
315
|
```
|
294
316
|
|
295
|
-
**NOTE:**
|
317
|
+
**NOTE:** There is no way to invalidate the cache when you upgrade Ruby Next (e.g., due to the bug fixes), so you should do this manually.
|
296
318
|
|
297
319
|
## `uby-next`
|
298
320
|
|
321
|
+
_This is [not a typo](https://github.com/ruby-next/ruby-next/pull/8), that’s the way `ruby -ruby-next` works: it’s equal to `ruby -r uby-next`, and [`uby-next.rb`](https://github.com/ruby-next/ruby-next/blob/master/lib/uby-next.rb) is a special file that activates the runtime mode._
|
322
|
+
|
299
323
|
You can also enable runtime mode by requiring `uby-next` while running a Ruby executable:
|
300
324
|
|
301
325
|
```sh
|
@@ -328,7 +352,7 @@ require:
|
|
328
352
|
- ruby-next/rubocop
|
329
353
|
```
|
330
354
|
|
331
|
-
|
355
|
+
You must set `TargetRubyVersion: next` to make RuboCop use a Ruby Next parser.
|
332
356
|
|
333
357
|
Alternatively, you can load the patch from the command line by running: `rubocop -r ruby-next/rubocop ...`.
|
334
358
|
|
@@ -349,48 +373,33 @@ This includes:
|
|
349
373
|
- Features proposed in [Ruby bug tracker](https://bugs.ruby-lang.org/) (_proposed_)
|
350
374
|
- Features once merged to master but got reverted.
|
351
375
|
|
352
|
-
These features
|
376
|
+
These features are disabled by default, you must opt-in in one of the following ways:
|
353
377
|
|
354
|
-
|
378
|
+
- Add `--edge` or `--proposed` option to `nextify` command when using CLI.
|
379
|
+
- Enable programmatically when using a runtime mode:
|
355
380
|
|
356
|
-
|
357
|
-
|
358
|
-
-
|
359
|
-
|
360
|
-
### Prerequisites
|
361
|
-
|
362
|
-
Our own version of [parser][next_parser] gem is hosted on Github Package Registry. That makes the installation process a bit more complicated than usual.
|
363
|
-
|
364
|
-
You must obtain an access token to use it. See the [GPR docs](https://help.github.com/en/github/managing-packages-with-github-package-registry/configuring-rubygems-for-use-with-github-package-registry#authenticating-to-github-package-registry).
|
365
|
-
|
366
|
-
### Installing with Bundler
|
381
|
+
```ruby
|
382
|
+
# It's important to load language module first
|
383
|
+
require "ruby-next/language"
|
367
384
|
|
368
|
-
|
385
|
+
require "ruby-next/language/edge"
|
386
|
+
# or
|
387
|
+
require "ruby-next/language/proposed"
|
369
388
|
|
370
|
-
|
371
|
-
|
389
|
+
# and then activate the runtime mode
|
390
|
+
require "ruby-next/language/runtime"
|
391
|
+
# or require "ruby-next/language/bootsnap"
|
372
392
|
```
|
373
393
|
|
374
|
-
|
375
|
-
|
376
|
-
```ruby
|
377
|
-
source "https://rubygems.pkg.github.com/ruby-next" do
|
378
|
-
gem "parser", "~> 2.7.0.100", "< 2.7.1"
|
379
|
-
end
|
380
|
-
|
381
|
-
gem "ruby-next"
|
382
|
-
```
|
394
|
+
- Set `RUBY_NEXT_EDGE=1` or `RUBY_NEXT_PROPOSED=1` environment variable.
|
383
395
|
|
384
|
-
|
396
|
+
### Supported edge features
|
385
397
|
|
386
|
-
|
398
|
+
Not yet.
|
387
399
|
|
388
|
-
|
400
|
+
### Supported proposed features
|
389
401
|
|
390
|
-
|
391
|
-
gem install parser -v "~> 2.7.0.100" -v "< 2.7.1" --source "https://USERNAME:ACCESS_TOKEN@rubygems.pkg.github.com/ruby-next"
|
392
|
-
gem install ruby-next
|
393
|
-
```
|
402
|
+
- _Method reference_ operator (`.:`) ([link](https://bugs.ruby-lang.org/issues/13581)).
|
394
403
|
|
395
404
|
## Contributing
|
396
405
|
|
data/lib/ruby-next/cli.rb
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
require "fileutils"
|
4
4
|
require "pathname"
|
5
5
|
|
6
|
+
require "ruby-next/language"
|
7
|
+
|
6
8
|
module RubyNext
|
7
9
|
module Commands
|
8
10
|
class Nextify < Base
|
@@ -38,9 +40,12 @@ module RubyNext
|
|
38
40
|
@single_version = true
|
39
41
|
end
|
40
42
|
|
41
|
-
opts.on("--
|
42
|
-
require "ruby-next/language/
|
43
|
-
|
43
|
+
opts.on("--edge", "Enable edge (master) Ruby features") do |val|
|
44
|
+
require "ruby-next/language/edge"
|
45
|
+
end
|
46
|
+
|
47
|
+
opts.on("--proposed", "Enable proposed/experimental Ruby features") do |val|
|
48
|
+
require "ruby-next/language/proposed"
|
44
49
|
end
|
45
50
|
|
46
51
|
opts.on(
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "parser/
|
3
|
+
require "parser/rubynext"
|
4
4
|
|
5
5
|
module RubyNext
|
6
6
|
module Language
|
@@ -10,7 +10,7 @@ module RubyNext
|
|
10
10
|
|
11
11
|
class << self
|
12
12
|
def parser
|
13
|
-
::Parser::
|
13
|
+
::Parser::RubyNext.new(Builder.new).tap do |prs|
|
14
14
|
prs.diagnostics.tap do |diagnostics|
|
15
15
|
diagnostics.all_errors_are_fatal = true
|
16
16
|
end
|
data/lib/ruby-next/language.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
gem "parser", ">= 2.
|
3
|
+
gem "ruby-next-parser", ">= 2.8.0.0"
|
4
4
|
gem "unparser", ">= 0.4.7"
|
5
5
|
|
6
6
|
require "set"
|
@@ -166,9 +166,12 @@ module RubyNext
|
|
166
166
|
require "ruby-next/language/rewriters/endless_range"
|
167
167
|
rewriters << Rewriters::EndlessRange
|
168
168
|
|
169
|
-
if ENV["
|
170
|
-
require "ruby-next/language/
|
171
|
-
|
169
|
+
if ENV["RUBY_NEXT_EDGE"] == "1"
|
170
|
+
require "ruby-next/language/edge"
|
171
|
+
end
|
172
|
+
|
173
|
+
if ENV["RUBY_NEXT_PROPOSED"] == "1"
|
174
|
+
require "ruby-next/language/proposed"
|
172
175
|
end
|
173
176
|
end
|
174
177
|
end
|
data/lib/ruby-next/rubocop.rb
CHANGED
@@ -1,7 +1,50 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# This file contains patches to RuboCop to support
|
4
|
-
# edge features and fix some bugs with 2.7 syntax
|
4
|
+
# edge features and fix some bugs with 2.7+ syntax
|
5
|
+
|
6
|
+
require "parser/ruby-next/version"
|
7
|
+
|
8
|
+
module RuboCop
|
9
|
+
# Transform Ruby Next parser version to a float, e.g.: "2.8.0.1" => 2.801
|
10
|
+
RUBY_NEXT_VERSION = Parser::NEXT_VERSION.match(/(^\d+)\.(.+)$/)[1..-1].map { |part| part.delete(".") }.join(".").to_f
|
11
|
+
|
12
|
+
class TargetRuby
|
13
|
+
class RuboCopNextConfig < RuboCopConfig
|
14
|
+
private
|
15
|
+
|
16
|
+
def find_version
|
17
|
+
version = @config.for_all_cops["TargetRubyVersion"]
|
18
|
+
return unless version == "next"
|
19
|
+
|
20
|
+
RUBY_NEXT_VERSION
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
new_rubies = KNOWN_RUBIES + [RUBY_NEXT_VERSION]
|
25
|
+
remove_const :KNOWN_RUBIES
|
26
|
+
const_set :KNOWN_RUBIES, new_rubies
|
27
|
+
|
28
|
+
new_sources = [RuboCopNextConfig] + SOURCES
|
29
|
+
remove_const :SOURCES
|
30
|
+
const_set :SOURCES, new_sources
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
module RuboCop
|
35
|
+
class ProcessedSource
|
36
|
+
module ParserClassExt
|
37
|
+
def parser_class(version)
|
38
|
+
return super unless version == RUBY_NEXT_VERSION
|
39
|
+
|
40
|
+
require "parser/rubynext"
|
41
|
+
Parser::RubyNext
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
prepend ParserClassExt
|
46
|
+
end
|
47
|
+
end
|
5
48
|
|
6
49
|
module RuboCop
|
7
50
|
module AST
|
data/lib/ruby-next/version.rb
CHANGED
data/lib/uby-next.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-next-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.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-
|
11
|
+
date: 2020-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: parser
|
14
|
+
name: ruby-next-parser
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.
|
19
|
+
version: 2.8.0.0
|
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.
|
26
|
+
version: 2.8.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: unparser
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -84,8 +84,10 @@ files:
|
|
84
84
|
- lib/ruby-next/core_ext.rb
|
85
85
|
- lib/ruby-next/language.rb
|
86
86
|
- lib/ruby-next/language/bootsnap.rb
|
87
|
+
- lib/ruby-next/language/edge.rb
|
87
88
|
- lib/ruby-next/language/eval.rb
|
88
89
|
- lib/ruby-next/language/parser.rb
|
90
|
+
- lib/ruby-next/language/proposed.rb
|
89
91
|
- lib/ruby-next/language/rewriters/args_forward.rb
|
90
92
|
- lib/ruby-next/language/rewriters/base.rb
|
91
93
|
- lib/ruby-next/language/rewriters/endless_range.rb
|