ruby2js 4.2.2 → 5.0.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: 0ce807defe8cfd9921c4696cadb5081fff15af23ed029bbd2ed490617f88b76f
4
- data.tar.gz: f2372abc0b0bdfa2af796d952a4c4987abad12d13595cb3fad85435367f0e690
3
+ metadata.gz: 40cd0d8969ad8042e83eaad5d0c870a05e949907a8d8429ca295f12ccdce5b45
4
+ data.tar.gz: f03789a32881ceca5fb7310e9e88c96882a76a9782c8940bdfe01bf00354fcef
5
5
  SHA512:
6
- metadata.gz: 500017171aa08ac86156367f21f5059d39201b93d0d8c15157e82f85d9e729a8d9fdae10fbb5778ac4c7055ec7c8e88de978567f6d9cf8a7d3723da67662913e
7
- data.tar.gz: 02621f8a80f5857c9a2537d2824c11f31e692ceea2df782b018786bd3415abeb08c62b62d5ce2be98ce713d164998298481f2ffafc9aa2b71ea18a45e4ce2e10
6
+ metadata.gz: 719e4a55b5eb62ffd31e53eeeebfb80140d0692d3cf7675a33eb10188d1845267b4a35fe3590ed589af49c9f576430c261e568184a8a13675036510fdc01493a
7
+ data.tar.gz: d4a0962d3534066225b8500b20af25124784de5ac7d5b62d25d363b8d781d09d4a359ef2fbd945ccd2aa7b48f34b8d3564e52b18bb15c09df7e0da0b01115e42
data/README.md CHANGED
@@ -7,7 +7,7 @@ Minimal yet extensible Ruby to JavaScript conversion.
7
7
  [![Gitter](https://badges.gitter.im/ruby2js/community.svg)](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
- License
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
- parse @ast.updated(:lvasgn, [name.children.first, value]), @state
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
- process S(:send, s(:send, s(:const, nil, :Array), :new,
446
- s(:send, args.first, :+, s(:int, 1))), :join, target)
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
@@ -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
@@ -38,6 +38,6 @@ Tilt.register 'rb', Ruby2JSTemplate
38
38
  helpers do
39
39
  def ruby2js(*args)
40
40
  content_type 'application/javascript'
41
- render('rb', *args)
41
+ render('rb', *args).to_s
42
42
  end
43
43
  end
@@ -1,8 +1,8 @@
1
1
  module Ruby2JS
2
2
  module VERSION #:nodoc:
3
- MAJOR = 4
4
- MINOR = 2
5
- TINY = 2
3
+ MAJOR = 5
4
+ MINOR = 0
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
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.3".freeze)
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.2.2
4
+ version: 5.0.0
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: 2021-12-07 00:00:00.000000000 Z
12
+ date: 2022-05-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: parser
@@ -187,14 +187,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
187
187
  requirements:
188
188
  - - ">="
189
189
  - !ruby/object:Gem::Version
190
- version: '2.3'
190
+ version: '2.7'
191
191
  required_rubygems_version: !ruby/object:Gem::Requirement
192
192
  requirements:
193
193
  - - ">="
194
194
  - !ruby/object:Gem::Version
195
195
  version: '0'
196
196
  requirements: []
197
- rubygems_version: 3.1.6
197
+ rubygems_version: 3.1.4
198
198
  signing_key:
199
199
  specification_version: 4
200
200
  summary: Minimal yet extensible Ruby to JavaScript conversion.