ruby2js 4.2.1 → 5.0.1

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: 8d723e9a782365d2969837ecd087655b127e0750884ae407282ab55986c4b8d3
4
- data.tar.gz: 6823e27e0b0786f90a1920255a5abe20cf9850c547a0e765d25dcc87aa5ce216
3
+ metadata.gz: 856cba477f40164ac46c0289d53f7a650125a39ef83f8fd00404c61fd35e81f1
4
+ data.tar.gz: 4a8799549c286b30ea340fd0181e615d1b7c1c725f7450310b02888692210083
5
5
  SHA512:
6
- metadata.gz: 5ff0eae448b2a3f671b04708b69f36a03dbe0c0d51d5b661f224b68d7acc98d0489da2de6050739e5ce59d9f298763a7b11235573e408d6d4a8dab6665dbd5e2
7
- data.tar.gz: e7301a5e3d5ccbc970fb034123791b947490b38c1727fa0de19f4f23b5866cc354422fc2a67654f45854564a0b0c9467d1067fb5d6f3d02bdfa6a2afa167e0f7
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
  [![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
@@ -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
@@ -125,7 +125,7 @@ module Ruby2JS
125
125
  *process_all(pair.children))
126
126
  end
127
127
  elsif arg.type == :str
128
- init << s(:send, s(:gvar, :$_), :content=, process(arg))
128
+ init << s(:send, s(:gvar, :$_), :textContent=, process(arg))
129
129
  else
130
130
  return super
131
131
  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,7 +1,7 @@
1
1
  module Ruby2JS
2
2
  module VERSION #:nodoc:
3
- MAJOR = 4
4
- MINOR = 2
3
+ MAJOR = 5
4
+ MINOR = 0
5
5
  TINY = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
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.1
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: 2021-11-13 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,7 +187,7 @@ 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
  - - ">="