ruby-next 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +23 -8
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 582bed282b94d002360230275370e6ba44507ee75294ea0e5a892a0d991e4bb2
|
4
|
+
data.tar.gz: 1e5a75bd9783c3e1f27b2285dbbbc9cc71e892bd4a4c2eab064beea568f32424
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71d9afb628d2cff983b6a419c9bec6c8b1635af9aa70b40a8fd59e6e9daa95e78cc204fb84e02af2c6789e4f22622d093e04414b5618129c956fc3082b529090
|
7
|
+
data.tar.gz: e76d9077c8a7cda3351a4bb96b3836236b7d0ec7d0efabbdc3f192c51bd538445254fe9c7a8085d7c00b72647280a3d7ed5e8f5174f5d6074c900ba1482ea422
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
## master
|
4
4
|
|
5
|
+
## 1.0.2 (2024-02-23)
|
6
|
+
|
7
|
+
- Automatically mark context as dirty if `#safe_rewrite` modifies source code. ([@palkan][])
|
8
|
+
|
9
|
+
- Add `context.path` to rewriters to access the current file path (if any). ([@palkan][])
|
10
|
+
|
5
11
|
## 1.0.1 (2024-01-28)
|
6
12
|
|
7
13
|
- Fix using Data with inheritance (`class X < Data.define(...)`). ([@palkan][])
|
data/README.md
CHANGED
@@ -170,7 +170,7 @@ Ruby 3.2 has introduced a new core class—[Data](https://bugs.ruby-lang.org/iss
|
|
170
170
|
|
171
171
|
If you want to opt-out from loading Data backport, you must set the `RUBY_NEXT_DISABLE_DATA` env variable to `true`.
|
172
172
|
|
173
|
-
#### Known limitations
|
173
|
+
#### Known limitations when using Data
|
174
174
|
|
175
175
|
Currently, passing Hash as a last positional argument to `Data.new` is not supported in Ruby <3.0 (due to the difference in keyword arguments handling). We recommend always using keyword arguments when initializing Data objects.
|
176
176
|
|
@@ -576,11 +576,7 @@ class MethodReferenceRewriter < RubyNext::Language::Rewriters::Text
|
|
576
576
|
MIN_SUPPORTED_VERSION = Gem::Version.new(RubyNext::NEXT_VERSION)
|
577
577
|
|
578
578
|
def safe_rewrite(source)
|
579
|
-
source.gsub(/\.:([\w_]+)
|
580
|
-
context.track! self
|
581
|
-
|
582
|
-
".method(:#{$1})"
|
583
|
-
end
|
579
|
+
source.gsub(/\.:([\w_]+)/, '.method(:\1)')
|
584
580
|
end
|
585
581
|
end
|
586
582
|
|
@@ -588,9 +584,28 @@ end
|
|
588
584
|
RubyNext::Language.rewriters << MethodReferenceRewriter
|
589
585
|
```
|
590
586
|
|
591
|
-
The `
|
587
|
+
The `#safe_rewrite` method operates on the normalized source code (i.e., without comments and string literals). It's useful when you want to avoid transpiling inside strings or comments. If you want to transpile the original contents, you can use the `#rewrite` method instead. For example, if you want to rewrite comments:
|
588
|
+
|
589
|
+
```ruby
|
590
|
+
|
591
|
+
class NoteDateRewriter < RubyNext::Language::Rewriters::Text
|
592
|
+
NAME = "note-comment-date"
|
593
|
+
MIN_SUPPORTED_VERSION = Gem::Version.new(RubyNext::NEXT_VERSION)
|
594
|
+
|
595
|
+
def rewrite(source)
|
596
|
+
source.gsub("# NOTE:") do |_match|
|
597
|
+
context.track!(self)
|
598
|
+
"# NOTE (#{Date.today}):"
|
599
|
+
end
|
600
|
+
end
|
601
|
+
end
|
602
|
+
|
603
|
+
RubyNext::Language.rewriters << NoteDateRewriter
|
604
|
+
```
|
605
|
+
|
606
|
+
Note that we use the `context` object in the example above. It is responsible for tracking if the rewriter was used for the current file. You must call the `context.track!` method to mark the file as _dirty_ (i.e., it should be transpiled). The input parameter (`source`) is the Ruby source code of the file being transpiled and the output must be the transpiled source code. When using `#safe_rewrite`, marking content as dirty explicitly is not necessary.
|
592
607
|
|
593
|
-
|
608
|
+
### Using parser combinators (Paco)
|
594
609
|
|
595
610
|
Under the hood, `#safe_rewrite` uses [Paco][] to parse the source and separate string literals from the rest of the code. You can also leverage [Paco][] in your text rewriters, if you want more control on the parsing process. For better experience, we provide a DSL to define a custom parser and the `#parse` method to use it. Here is an example of implementing the `.:` operator using a Paco parser:
|
596
611
|
|
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: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Dementyev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-next-core
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.0.
|
19
|
+
version: 1.0.2
|
20
20
|
type: :runtime
|
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: 1.0.
|
26
|
+
version: 1.0.2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: ruby-next-parser
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|