ruby-next 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -1
  3. data/LICENSE.txt +1 -1
  4. data/README.md +74 -37
  5. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6cc67691b20d3fa1a528a3f42d306f634b4b23aa8d5d876c4441e5cfdc08bbd9
4
- data.tar.gz: ba3efeed90aefc8ab2f50979792445e5dae7dc3447715bdc38155889459b8807
3
+ metadata.gz: 6424a38e36c431e8c6c976ac4a0230c4a212ec125ad849ceff36a7a50ce38733
4
+ data.tar.gz: 736af6cc9b1d2ad462473706d84a1be8d579e5c80f7a7cf0a04a481a8d268a15
5
5
  SHA512:
6
- metadata.gz: 7fd55f852c960fe4230abb6ebd512bd0b22b084659486484bfc45b3b7ee987ff77fcc9ab5932e880175063ea492bb746dc88d2e0a230fd77b9dfee78b275d88f
7
- data.tar.gz: 25c136bb7761113535006f1de10fe34fafd69520c633b7693b59afca63eb7b6b64593529f80c61b494325c3a6bd0864bfd30a011502dcbd4ff41fb54911d0f4e
6
+ metadata.gz: 46f0a20049218e02c7d7767da662afbdabb77fb69fad18647e0e1418f9ab09da52a9c558eaeb65ea2e6516a245656f2a6f3e84a5db28d634b9acd20742507388
7
+ data.tar.gz: a0fe8a798e2ad64273321650959d30ef4b259349d8c0db451e2c6392ace695aef5c813c3167315b76d57f8041c792f8c49bfc29988803091fb0f8198b5d6617e
data/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 0.5.0 (2020-03-20)
6
+
7
+ - Add `rewrite` transpiler mode. ([@palkan][])
8
+
9
+ Add support for rewriting the source code instead of rebuilding it from scratch to
10
+ preserve the original layout and improve the debugging experience.
11
+
5
12
  ## 0.4.0 (2020-03-09)
6
13
 
7
14
  - Optimize pattern matching transpiled code. ([@palkan][])
@@ -67,7 +74,7 @@ p a #=> 1
67
74
 
68
75
  - Support hash pattern in array and vice versa. ([@palkan][])
69
76
 
70
- - Handle multile `-e` in `uby-next`. ([@palkan][])
77
+ - Handle multiple `-e` in `uby-next`. ([@palkan][])
71
78
 
72
79
  ## 0.1.0 (2019-11-16)
73
80
 
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2019 Vladimir Dementyev
3
+ Copyright (c) 2019-2020 Vladimir Dementyev
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -24,6 +24,19 @@ That's why Ruby Next implements the `master` features as fast as possible.
24
24
 
25
25
  - [Ruby Next: Make old Rubies quack like a new one](https://noti.st/palkan/j3i2Dr/ruby-next-make-old-rubies-quack-like-a-new-one) (RubyConf 2019)
26
26
 
27
+ ## Table of contents
28
+
29
+ - [Overview](#overview)
30
+ - [Polyfills](#using-only-polyfills)
31
+ - [Transpiling](#transpiling)
32
+ - [Modes](#transpiler-modes)
33
+ - [CLI](#cli)
34
+ - [Using in gems](#integrating-into-a-gem-development)
35
+ - [Runtime usage](#runtime-usage)
36
+ - [Bootsnap integration](#using-with-bootsnap)
37
+ - [`ruby -ruby-next`](#uby-next)
38
+ - [Proposed & edge features](#proposed-and-edge-features)
39
+
27
40
  ## Overview
28
41
 
29
42
  Ruby Next consists of two parts: **core** and **language**.
@@ -75,14 +88,16 @@ require "ruby-next/core_ext"
75
88
  The following _rule of thumb_ is recommended when choosing between refinements and monkey-patches:
76
89
 
77
90
  - Use refinements for libraries development (to avoid conflicts with others code)
78
- - Using core extensions could be considered for application development (no need to think about `using RubyNext`); this approach could potentially lead to conflicts with dependendices (if these dependencies are not using refinements 🙂)
91
+ - Using core extensions could be considered for application development (no need to think about `using RubyNext`); this approach could potentially lead to conflicts with dependencies (if these dependencies are not using refinements 🙂)
79
92
  - Use core extensions if refinements are not supported by your platform
80
93
 
81
94
  [**The list of supported APIs.**][features_core]
82
95
 
83
- ## Transpiling, or using edge Ruby syntax features
96
+ ## Transpiling
97
+
98
+ Ruby Next allows you to transpile\* edge Ruby syntax to older versions.
84
99
 
85
- Ruby Next transpiler relies on two libraries: [parser][] and [unparser][].
100
+ Transpiler relies on two libraries: [parser][] and [unparser][].
86
101
 
87
102
  **NOTE:** The "official" parser gem only supports the latest stable Ruby version, while Ruby Next aims to support edge and experimental Ruby features. To enable them, you should use our version of Parser (see [instructions](#using-ruby-next-parser) below).
88
103
 
@@ -103,40 +118,23 @@ gem install ruby-next
103
118
 
104
119
  [**The list of supported syntax features.**][features_syntax]
105
120
 
106
- ### Integrating into a gem development
121
+ ### Transpiler modes
107
122
 
108
- We recommend _pre-transpiling_ source code to work with older versions before releasing it.
123
+ Ruby Next currently provides two different modes of generating transpiled code: _AST_ and _rewrite_.
109
124
 
110
- This is how you can do that with Ruby Next:
125
+ 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.
111
126
 
112
- - Write source code using the modern/edge Ruby syntax.
127
+ 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).
113
128
 
114
- - Generate transpiled code by calling `ruby-next nextify ./lib` (e.g., before releasing or pushing to VCS).
129
+ By default, we use the AST mode. That could likely change in the future when we collect enough feedback on the rewrite mode and fix potential bugs.
115
130
 
116
- This will produce `lib/.rbnext` folder containing the transpiled files, `lib/.rbnext/2.6`, `lib/.rbnext/2.7`. The version in the path indicates which Ruby version is required for the original functionality. Only the source files containing new syntax are added to this folder.
131
+ The main benefit of the rewrite mode is that it preserves the original code line numbers and layout, which is especially useful in debugging.
117
132
 
118
- **NOTE:** Do not edit these files manually, either run linters/type checkers/whatever against these files.
133
+ You can change the transpiler mode:
119
134
 
120
- - Add the following code to your gem's _entrypoint_ (the file that is required first and contains other `require`-s):
121
-
122
- ```ruby
123
- require "ruby-next/language/setup"
124
-
125
- RubyNext::Language.setup_gem_load_path
126
- ```
127
-
128
- The `setup_gem_load_path` does the following:
129
-
130
- - Resolves the current ruby version.
131
- - Checks whether there are directories corresponding to the current and earlier\* Ruby versions within the `.rbnext` folder.
132
- - Add the path to this directory to the `$LOAD_PATH` before the path to the gem's directory.
133
-
134
- That's why need an _entrypoint_: all the subsequent `require` calls will load the transpiled files instead of the original ones
135
- due to the way feature resolving works in Ruby (scanning the `$LOAD_PATH` and halting as soon as the matching file is found).
136
-
137
- **NOTE:** `require_relative` should be avoided due to the way we _hijack_ the features loading mechanism.
138
-
139
- \* Ruby Next avoids storing duplicates; instead, only the code for the earlier version is created and is assumed to be used with other versions. For example, if the transpiled code is the same for Ruby 2.5 and Ruby 2.6, only the `.rbnext/2.7/path/to/file.rb` is kept. That's why multiple entries are added to the `$LOAD_PATH` (`.rbnext/2.6` and `.rbnext/2.7` in the specified order for Ruby 2.5 and only `.rbnext/2.7` for Ruby 2.6).
135
+ - From code by setting `RubyNext::Language.mode = :ast` or `RubyNext::Language.mode = :rewrite`.
136
+ - Via environmental variable `RUBY_NEXT_TRANSPILE_MODE=rewrite`.
137
+ - Via CLI option ([see below](#cli)).
140
138
 
141
139
  ## CLI
142
140
 
@@ -155,6 +153,7 @@ Usage: ruby-next nextify DIRECTORY_OR_FILE [options]
155
153
  --min-version=VERSION Specify the minimum Ruby version to support
156
154
  --single-version Only create one version of a file (for the earliest Ruby version)
157
155
  --enable-method-reference Enable reverted method reference syntax (requires custom parser)
156
+ --transpile-mode=MODE Transpiler mode (ast or rewrite). Default: ast
158
157
  --[no-]refine Do not inject `using RubyNext`
159
158
  -h, --help Print help
160
159
  -V Turn on verbose mode
@@ -191,7 +190,7 @@ Usage: ruby-next core_ext [options]
191
190
  -V Turn on verbose mode
192
191
  ```
193
192
 
194
- The most common usecase is to backport the APIs required by pattern matching. You can do this, for example,
193
+ The most common use-case is to backport the APIs required by pattern matching. You can do this, for example,
195
194
  by including only monkey-patches containing the `"deconstruct"` in their names:
196
195
 
197
196
  ```sh
@@ -215,7 +214,42 @@ $ ruby-next core_ext -l --name=filter --name=deconstruct
215
214
  - StructDeconstruct
216
215
  ```
217
216
 
218
- ## Runtime mode
217
+ ### Integrating into a gem development
218
+
219
+ We recommend _pre-transpiling_ source code to work with older versions before releasing it.
220
+
221
+ This is how you can do that with Ruby Next:
222
+
223
+ - Write source code using the modern/edge Ruby syntax.
224
+
225
+ - Generate transpiled code by calling `ruby-next nextify ./lib` (e.g., before releasing or pushing to VCS).
226
+
227
+ This will produce `lib/.rbnext` folder containing the transpiled files, `lib/.rbnext/2.6`, `lib/.rbnext/2.7`. The version in the path indicates which Ruby version is required for the original functionality. Only the source files containing new syntax are added to this folder.
228
+
229
+ **NOTE:** Do not edit these files manually, either run linters/type checkers/whatever against these files.
230
+
231
+ - Add the following code to your gem's _entrypoint_ (the file that is required first and contains other `require`-s):
232
+
233
+ ```ruby
234
+ require "ruby-next/language/setup"
235
+
236
+ RubyNext::Language.setup_gem_load_path
237
+ ```
238
+
239
+ The `setup_gem_load_path` does the following:
240
+
241
+ - Resolves the current ruby version.
242
+ - Checks whether there are directories corresponding to the current and earlier\* Ruby versions within the `.rbnext` folder.
243
+ - Add the path to this directory to the `$LOAD_PATH` before the path to the gem's directory.
244
+
245
+ That's why need an _entrypoint_: all the subsequent `require` calls will load the transpiled files instead of the original ones
246
+ due to the way feature resolving works in Ruby (scanning the `$LOAD_PATH` and halting as soon as the matching file is found).
247
+
248
+ **NOTE:** `require_relative` should be avoided due to the way we _hijack_ the features loading mechanism.
249
+
250
+ \* Ruby Next avoids storing duplicates; instead, only the code for the earlier version is created and is assumed to be used with other versions. For example, if the transpiled code is the same for Ruby 2.5 and Ruby 2.6, only the `.rbnext/2.7/path/to/file.rb` is kept. That's why multiple entries are added to the `$LOAD_PATH` (`.rbnext/2.6` and `.rbnext/2.7` in the specified order for Ruby 2.5 and only `.rbnext/2.7` for Ruby 2.6).
251
+
252
+ ## Runtime usage
219
253
 
220
254
  It is also possible to transpile Ruby source code in run-time via Ruby Next.
221
255
 
@@ -270,20 +304,23 @@ RUBYOPT="-ruby-next" ruby my_ruby_script.rb
270
304
  ruby -ruby-next -e "puts [2, 4, 5].tally"
271
305
  ```
272
306
 
273
- ## Unofficial/experimental features
307
+ ## Proposed and edge features
274
308
 
275
- Ruby Next also provides support for some features not-yet-merged into Ruby master (or reverted).
309
+ Ruby Next aims to bring edge and proposed features to Ruby community before they (hopefully) reach an official Ruby release.
310
+ This includes:
311
+
312
+ - Features already merged to [master](https://github.com/ruby/ruby) (_edge_)
313
+ - Features proposed in [Ruby bug tracker](https://bugs.ruby-lang.org/) (_proposed_)
314
+ - Features once merged to master but got reverted.
276
315
 
277
316
  These features require a [custom parser](#using-ruby-next-parser).
278
317
 
279
- Currenly, the only such feature is the [_method reference_ operator](https://bugs.ruby-lang.org/issues/13581):
318
+ Currently, the only such feature is the [_method reference_ operator](https://bugs.ruby-lang.org/issues/13581):
280
319
 
281
320
  - Add `--enable-method-reference` option to `nextify` command when using CLI.
282
321
  - OR add it programmatically when using a runtime mode (see [example](https://github.com/ruby-next/ruby-next/blob/master/default.mspec)).
283
322
  - OR set `RUBY_NEXT_ENABLE_METHOD_REFERENCE=1` environment variable (works with CLI as well).
284
323
 
285
- ## Using Ruby Next parser
286
-
287
324
  ### Prerequisites
288
325
 
289
326
  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.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-next
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.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-09 00:00:00.000000000 Z
11
+ date: 2020-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-next-core
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 2.7.0.0
33
+ version: 2.7.0.5
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 2.7.0.0
40
+ version: 2.7.0.5
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: unparser
43
43
  requirement: !ruby/object:Gem::Requirement