ruby-next-core 0.5.3 → 0.6.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: 9779cf5c0dea7fff2e3185f6409a7ea21287d4d4b38466e7393c2cebb97d128a
4
- data.tar.gz: b1ef29ce986cbaa595e3a5e257674869d3e7d5842185385728d5f70eb81996fc
3
+ metadata.gz: 5447b309915122d9f6dc9a366c34a566891c9f9cc569722c0999e020ef891d6b
4
+ data.tar.gz: 9c2da837b1c9e4d2d36ea8665a90f7d3c004d6175b1d0e82262396846ac00f6a
5
5
  SHA512:
6
- metadata.gz: 26de1a278bceaa3423b21e4f7b1c6c791e9fe3e42d319864fd0041d29f86b5946095ea42e03811169aa41be1220e4726ec57a24f19f939ec8fb197662505f2f1
7
- data.tar.gz: 9ef7af94930ac374f7732e1ff71b57b4ee135be8609e0343314117f362af994c177dfa2541cfcc0802029320341e3c509b11ef8a2fdf0ab0e5d80451e902d803
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 a predictable behaviour. That's why we recommend using refinements for gems development.
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 a different formatting.
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:** 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.
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
- **NOTE:** You should use `TargetRubyVersion: 2.7`.
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 require a [custom parser](#using-ruby-next-parser).
376
+ These features are disabled by default, you must opt-in in one of the following ways:
353
377
 
354
- Currently, the only such feature is the [_method reference_ operator](https://bugs.ruby-lang.org/issues/13581):
378
+ - Add `--edge` or `--proposed` option to `nextify` command when using CLI.
379
+ - Enable programmatically when using a runtime mode:
355
380
 
356
- - Add `--enable-method-reference` option to `nextify` command when using CLI.
357
- - OR add it programmatically when using a runtime mode (see [example](https://github.com/ruby-next/ruby-next/blob/master/default.mspec)).
358
- - OR set `RUBY_NEXT_ENABLE_METHOD_REFERENCE=1` environment variable (works with CLI as well).
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
- First, configure your bundler to access GPR:
385
+ require "ruby-next/language/edge"
386
+ # or
387
+ require "ruby-next/language/proposed"
369
388
 
370
- ```sh
371
- bundle config --local https://rubygems.pkg.github.com/ruby-next USERNAME:ACCESS_TOKEN
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
- Then, add to your Gemfile:
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
- **NOTE:** we don't add `parser` and `unparser` to the gem's runtime deps, 'cause they're not necessary if you only need polyfills.
396
+ ### Supported edge features
385
397
 
386
- ### Installing globally via `gem`
398
+ Not yet.
387
399
 
388
- You can install `ruby-next` globally by running the following commands:
400
+ ### Supported proposed features
389
401
 
390
- ```sh
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
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "ruby-next"
4
- require "ruby-next/language"
5
4
 
6
5
  require "ruby-next/commands/base"
7
6
  require "ruby-next/commands/nextify"
@@ -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("--enable-method-reference", "Enable reverted method reference syntax (requires custom parser)") do
42
- require "ruby-next/language/rewriters/method_reference"
43
- Language.rewriters << Language::Rewriters::MethodReference
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(
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Load edge Ruby features
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "parser/ruby27"
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::Ruby27.new(Builder.new).tap do |prs|
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
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Load experimental, proposed etc. Ruby features
4
+
5
+ require "ruby-next/language/rewriters/method_reference"
6
+ RubyNext::Language.rewriters << RubyNext::Language::Rewriters::MethodReference
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- gem "parser", ">= 2.7.0.0"
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["RUBY_NEXT_ENABLE_METHOD_REFERENCE"] == "1"
170
- require "ruby-next/language/rewriters/method_reference"
171
- RubyNext::Language.rewriters << RubyNext::Language::Rewriters::MethodReference
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
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyNext
4
- VERSION = "0.5.3"
4
+ VERSION = "0.6.0"
5
5
  end
data/lib/uby-next.rb CHANGED
@@ -1,5 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Activate all features
4
+ ENV["RUBY_NEXT_EDGE"] = "1"
5
+ ENV["RUBY_NEXT_PROPOSED"] = "1"
6
+
3
7
  require "ruby-next/language/runtime"
4
8
  require "ruby-next/core/runtime"
5
9
 
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.5.3
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-03-25 00:00:00.000000000 Z
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.7.0.5
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.7.0.5
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