ruby2js 4.2.1 → 5.0.1
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/README.md +13 -5
- data/lib/ruby2js/converter/match.rb +22 -1
- data/lib/ruby2js/filter/camelCase.rb +1 -1
- data/lib/ruby2js/filter/functions.rb +15 -4
- data/lib/ruby2js/filter/nokogiri.rb +1 -1
- data/lib/ruby2js/sinatra.rb +1 -1
- data/lib/ruby2js/version.rb +2 -2
- data/ruby2js.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 856cba477f40164ac46c0289d53f7a650125a39ef83f8fd00404c61fd35e81f1
|
4
|
+
data.tar.gz: 4a8799549c286b30ea340fd0181e615d1b7c1c725f7450310b02888692210083
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 839bbb243e185cdf61b4c7a67e85595dcad52acdaadb4f053f08e1c41f60dfcc8bc9c3320670538976413299bf199c77ffcd5d4b70df232600673e4b8bc580c5
|
7
|
+
data.tar.gz: cbac1f4f24ae5292c65555a15185204e7128e22a54a257ef05132f9b7d4954a49b65db8dae6d8089b6b5e1a5682625ba6fd5778b0c68ba5748abf3c03c330901
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@ Minimal yet extensible Ruby to JavaScript conversion.
|
|
7
7
|
[](https://gitter.im/ruby2js/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
|
8
8
|
|
9
9
|
|
10
|
-
Documentation
|
10
|
+
## Documentation
|
11
11
|
---
|
12
12
|
|
13
13
|
* Visit **[ruby2js.com](https://www.ruby2js.com)** for detailed setup instructions and API reference.
|
@@ -15,8 +15,8 @@ Documentation
|
|
15
15
|
* [Try Ruby2JS online](https://ruby2js.com/demo)
|
16
16
|
|
17
17
|
|
18
|
-
Synopsis
|
19
|
-
|
18
|
+
## Synopsis
|
19
|
+
|
20
20
|
|
21
21
|
Basic:
|
22
22
|
|
@@ -44,9 +44,17 @@ Enable ES2015 support:
|
|
44
44
|
puts Ruby2JS.convert('"#{a}"', eslevel: 2015)
|
45
45
|
```
|
46
46
|
|
47
|
+
## Testing
|
47
48
|
|
48
|
-
|
49
|
-
|
49
|
+
1. Run `bundle install`
|
50
|
+
2. Run `bundle exec rake test_all`
|
51
|
+
|
52
|
+
## Release Process for Maintainers
|
53
|
+
|
54
|
+
1. Update the version in both `packages/ruby2js/package.json` and `lib/ruby2js/version`, ensuring they match.
|
55
|
+
2. Run `bundle exec rake release_core`
|
56
|
+
|
57
|
+
## License
|
50
58
|
|
51
59
|
(The MIT License)
|
52
60
|
|
@@ -1,7 +1,28 @@
|
|
1
1
|
module Ruby2JS
|
2
2
|
class Converter
|
3
3
|
handle :match_pattern do |value, name|
|
4
|
-
|
4
|
+
if name.type == :match_var
|
5
|
+
parse @ast.updated(:lvasgn, [name.children.first, value]), @state
|
6
|
+
elsif name.type == :hash_pattern and name.children.all? {|child| child.type == :match_var}
|
7
|
+
if es2015
|
8
|
+
put 'let { '
|
9
|
+
put name.children.map {|child| child.children[0].to_s}.join(', ')
|
10
|
+
put ' } = '
|
11
|
+
parse value
|
12
|
+
else
|
13
|
+
name.children.each_with_index do |child, index|
|
14
|
+
put @sep unless index == 0
|
15
|
+
put 'var '
|
16
|
+
put child.children[0].to_s
|
17
|
+
put ' = '
|
18
|
+
parse value
|
19
|
+
put '.'
|
20
|
+
put child.children[0].to_s
|
21
|
+
end
|
22
|
+
end
|
23
|
+
else
|
24
|
+
raise Error.new("complex match patterns are not supported", @ast)
|
25
|
+
end
|
5
26
|
end
|
6
27
|
end
|
7
28
|
end
|
@@ -69,7 +69,7 @@ module Ruby2JS
|
|
69
69
|
def handle_generic_node(node, node_type)
|
70
70
|
return node if node.type != node_type
|
71
71
|
|
72
|
-
if node.children[0] =~ /_.*[?!\w]$/ and !ALLOWLIST.include?(node.children[0].to_s)
|
72
|
+
if node.children[0].to_s =~ /_.*[?!\w]$/ and !ALLOWLIST.include?(node.children[0].to_s)
|
73
73
|
S(node_type , camelCase(node.children[0]), *node.children[1..-1])
|
74
74
|
else
|
75
75
|
node
|
@@ -442,8 +442,12 @@ module Ruby2JS
|
|
442
442
|
S(:send, s(:const, nil, :JSON), :stringify, process(target))
|
443
443
|
|
444
444
|
elsif method == :* and target.type == :str
|
445
|
-
|
446
|
-
|
445
|
+
if es2015
|
446
|
+
process S(:send, target, :repeat, args.first)
|
447
|
+
else
|
448
|
+
process S(:send, s(:send, s(:const, nil, :Array), :new,
|
449
|
+
s(:send, args.first, :+, s(:int, 1))), :join, target)
|
450
|
+
end
|
447
451
|
|
448
452
|
elsif [:is_a?, :kind_of?].include? method and args.length == 1
|
449
453
|
if args[0].type == :const
|
@@ -506,10 +510,10 @@ module Ruby2JS
|
|
506
510
|
s(:regexp, s(:str, '\A\s+') , s(:regopt)), s(:str, '')])
|
507
511
|
end
|
508
512
|
|
509
|
-
elsif method == :index
|
513
|
+
elsif method == :index and node.is_method?
|
510
514
|
process node.updated(nil, [target, :indexOf, *args])
|
511
515
|
|
512
|
-
elsif method == :rindex
|
516
|
+
elsif method == :rindex and node.is_method?
|
513
517
|
process node.updated(nil, [target, :lastIndexOf, *args])
|
514
518
|
|
515
519
|
elsif method == :class and args.length==0 and not node.is_method?
|
@@ -589,6 +593,13 @@ module Ruby2JS
|
|
589
593
|
super
|
590
594
|
end
|
591
595
|
|
596
|
+
elsif method == :chars and args.length == 0
|
597
|
+
if es2015
|
598
|
+
S(:send, s(:const, nil, :Array), :from, target)
|
599
|
+
else
|
600
|
+
super
|
601
|
+
end
|
602
|
+
|
592
603
|
else
|
593
604
|
super
|
594
605
|
end
|
data/lib/ruby2js/sinatra.rb
CHANGED
data/lib/ruby2js/version.rb
CHANGED
data/ruby2js.gemspec
CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.files = %w(ruby2js.gemspec README.md bin/ruby2js demo/ruby2js.rb) + Dir.glob("{lib}/**/*")
|
16
16
|
s.homepage = "http://github.com/rubys/ruby2js".freeze
|
17
17
|
s.licenses = ["MIT".freeze]
|
18
|
-
s.required_ruby_version = Gem::Requirement.new(">= 2.
|
18
|
+
s.required_ruby_version = Gem::Requirement.new(">= 2.7".freeze)
|
19
19
|
s.summary = "Minimal yet extensible Ruby to JavaScript conversion.".freeze
|
20
20
|
|
21
21
|
s.executables << 'ruby2js'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby2js
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Ruby
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-05-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: parser
|
@@ -187,7 +187,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
187
187
|
requirements:
|
188
188
|
- - ">="
|
189
189
|
- !ruby/object:Gem::Version
|
190
|
-
version: '2.
|
190
|
+
version: '2.7'
|
191
191
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
192
192
|
requirements:
|
193
193
|
- - ">="
|