ruby2js 4.2.0 → 4.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/demo/ruby2js.rb +2 -0
- data/lib/ruby2js/converter/block.rb +14 -0
- data/lib/ruby2js/filter/functions.rb +24 -0
- data/lib/ruby2js/version.rb +1 -1
- data/lib/ruby2js.rb +11 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d723e9a782365d2969837ecd087655b127e0750884ae407282ab55986c4b8d3
|
4
|
+
data.tar.gz: 6823e27e0b0786f90a1920255a5abe20cf9850c547a0e765d25dcc87aa5ce216
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ff0eae448b2a3f671b04708b69f36a03dbe0c0d51d5b661f224b68d7acc98d0489da2de6050739e5ce59d9f298763a7b11235573e408d6d4a8dab6665dbd5e2
|
7
|
+
data.tar.gz: e7301a5e3d5ccbc970fb034123791b947490b38c1727fa0de19f4f23b5866cc354422fc2a67654f45854564a0b0c9467d1067fb5d6f3d02bdfa6a2afa167e0f7
|
data/demo/ruby2js.rb
CHANGED
@@ -69,5 +69,19 @@ module Ruby2JS
|
|
69
69
|
parse s(@ast.children[0].type, *call.children, function), @state
|
70
70
|
end
|
71
71
|
end
|
72
|
+
|
73
|
+
# (numblock
|
74
|
+
# (send nil :x)
|
75
|
+
# 1
|
76
|
+
# (lvar :_1))
|
77
|
+
|
78
|
+
handle :numblock do |call, count, block|
|
79
|
+
parse s(:block,
|
80
|
+
call,
|
81
|
+
s(:args, *((1..count).map {|i| s(:arg, "_#{i}")})),
|
82
|
+
block
|
83
|
+
)
|
84
|
+
end
|
85
|
+
|
72
86
|
end
|
73
87
|
end
|
@@ -162,6 +162,9 @@ module Ruby2JS
|
|
162
162
|
elsif method == :to_f
|
163
163
|
process node.updated :send, [nil, :parseFloat, target, *args]
|
164
164
|
|
165
|
+
elsif method == :to_json
|
166
|
+
process node.updated :send, [s(:const, nil, :JSON), :stringify, target, *args]
|
167
|
+
|
165
168
|
elsif method == :sub and args.length == 2
|
166
169
|
if args[1].type == :str
|
167
170
|
args[1] = s(:str, args[1].children.first.gsub(/\\(\d)/, "$\\1"))
|
@@ -503,6 +506,12 @@ module Ruby2JS
|
|
503
506
|
s(:regexp, s(:str, '\A\s+') , s(:regopt)), s(:str, '')])
|
504
507
|
end
|
505
508
|
|
509
|
+
elsif method == :index
|
510
|
+
process node.updated(nil, [target, :indexOf, *args])
|
511
|
+
|
512
|
+
elsif method == :rindex
|
513
|
+
process node.updated(nil, [target, :lastIndexOf, *args])
|
514
|
+
|
506
515
|
elsif method == :class and args.length==0 and not node.is_method?
|
507
516
|
process node.updated(:attr, [target, :constructor])
|
508
517
|
|
@@ -515,6 +524,9 @@ module Ruby2JS
|
|
515
524
|
elsif method == :abs and args.length == 0
|
516
525
|
process S(:send, s(:const, nil, :Math), :abs, target)
|
517
526
|
|
527
|
+
elsif method == :round and args.length == 0
|
528
|
+
process S(:send, s(:const, nil, :Math), :round, target)
|
529
|
+
|
518
530
|
elsif method == :ceil and args.length == 0
|
519
531
|
process S(:send, s(:const, nil, :Math), :ceil, target)
|
520
532
|
|
@@ -570,6 +582,13 @@ module Ruby2JS
|
|
570
582
|
process S(:send, s(:attr, target, :prototype), :[]=, args[0],
|
571
583
|
s(:attr, s(:attr, target, :prototype), args[1].children[0]))
|
572
584
|
|
585
|
+
elsif method == :new and args.length == 2 and target == s(:const, nil, :Array)
|
586
|
+
if es2015
|
587
|
+
s(:send, S(:send, target, :new, args.first), :fill, args.last)
|
588
|
+
else
|
589
|
+
super
|
590
|
+
end
|
591
|
+
|
573
592
|
else
|
574
593
|
super
|
575
594
|
end
|
@@ -616,6 +635,11 @@ module Ruby2JS
|
|
616
635
|
node.updated nil, [process(call), process(node.children[1]),
|
617
636
|
s(:autoreturn, *process_all(node.children[2..-1]))]
|
618
637
|
|
638
|
+
elsif method == :index and call.children.length == 2
|
639
|
+
call = call.updated nil, [call.children.first, :findIndex]
|
640
|
+
node.updated nil, [process(call), process(node.children[1]),
|
641
|
+
s(:autoreturn, *process_all(node.children[2..-1]))]
|
642
|
+
|
619
643
|
elsif method == :map and call.children.length == 2
|
620
644
|
node.updated nil, [process(call), process(node.children[1]),
|
621
645
|
s(:autoreturn, *process_all(node.children[2..-1]))]
|
data/lib/ruby2js/version.rb
CHANGED
data/lib/ruby2js.rb
CHANGED
@@ -185,6 +185,17 @@ module Ruby2JS
|
|
185
185
|
# provide a method so filters can call 'super'
|
186
186
|
def on_sym(node); node; end
|
187
187
|
|
188
|
+
# convert numbered parameters block to a normal block
|
189
|
+
def on_numblock(node)
|
190
|
+
call, count, block = node.children
|
191
|
+
|
192
|
+
process s(:block,
|
193
|
+
call,
|
194
|
+
s(:args, *((1..count).map {|i| s(:arg, "_#{i}")})),
|
195
|
+
block
|
196
|
+
)
|
197
|
+
end
|
198
|
+
|
188
199
|
# convert map(&:symbol) to a block
|
189
200
|
def on_send(node)
|
190
201
|
if node.children.length > 2 and node.children.last.type == :block_pass
|
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.
|
4
|
+
version: 4.2.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-
|
12
|
+
date: 2021-11-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: parser
|