ruby2js 3.1.2 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -7
- data/lib/ruby2js/filter/functions.rb +49 -15
- data/lib/ruby2js/version.rb +2 -2
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2414f75bafbcf153ced6b3834b19513f4589d0745ca508eb2169fdc6c190c2f
|
4
|
+
data.tar.gz: b8847a24e1b7f96a5602c84034623c2f3847c17458b521d949fcbd5b9cb9c2b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 736f8322e18bad8b0e6b70a6c41337f0db73499193ae0b7137e703bd9093ff8ff30a91610d0db93f6a8b3e9f9df017f42025cb28799fc80d72fe10ddd07a2eb1
|
7
|
+
data.tar.gz: 3faea6f125e9ec36c292be5afda1bf9de5a79c41e1ff8b1c46715a3508d06f977e0eae91cdb543e49899e416ce04d8aa01785244067709b75b50a6fb58da90f1
|
data/README.md
CHANGED
@@ -220,9 +220,10 @@ the script.
|
|
220
220
|
* `.clear` becomes `.length = 0`
|
221
221
|
* `.delete` becomes `delete target[arg]`
|
222
222
|
* `.downcase` becomes `.toLowerCase`
|
223
|
-
* `.each` becomes `
|
224
|
-
* `.each_key` becomes `
|
225
|
-
* `.
|
223
|
+
* `.each` becomes `.forEach`
|
224
|
+
* `.each_key` becomes `for (i in ...) {}`
|
225
|
+
* `.each_pair` becomes `for (var key in item) {var value = item[key]; ...}`
|
226
|
+
* `.each_value` becomes `.forEach`
|
226
227
|
* `.each_with_index` becomes `.forEach`
|
227
228
|
* `.end_with?` becomes `.slice(-arg.length) == arg`
|
228
229
|
* `.empty?` becomes `.length == 0`
|
@@ -536,7 +537,7 @@ conversions are made:
|
|
536
537
|
* `def f(a, (foo, *bar))` becomes `function f(a, [foo, ...bar])`
|
537
538
|
* `def a(b=1)` becomes `function a(b=1)`
|
538
539
|
* `def a(*b)` becomes `function a(...b)`
|
539
|
-
* `.
|
540
|
+
* `.each_value` becomes `for (i of ...) {}`
|
540
541
|
* `a(*b)` becomes `a(...b)`
|
541
542
|
* `"#{a}"` becomes <code>\`${a}\`</code>
|
542
543
|
* `lambda {|x| x}` becomes `(x) => {return x}`
|
@@ -574,7 +575,7 @@ ES2017 support
|
|
574
575
|
When option `eslevel: 2017` is provided, the following additional
|
575
576
|
conversion is made by the `functions` filter:
|
576
577
|
|
577
|
-
* `.
|
578
|
+
* `.each_pair` becomes `for (let [key, value] of Object.entries()) {}'
|
578
579
|
|
579
580
|
ES2018 support
|
580
581
|
---
|
@@ -590,7 +591,7 @@ optional keyword arguments.
|
|
590
591
|
ES2019 support
|
591
592
|
---
|
592
593
|
|
593
|
-
When option `eslevel:
|
594
|
+
When option `eslevel: 2019` is provided, the following additional
|
594
595
|
conversion is made by the `functions` filter:
|
595
596
|
|
596
597
|
* `.flatten` becomes `.flat(Infinity)`
|
@@ -604,7 +605,7 @@ variable.
|
|
604
605
|
ES2020 support
|
605
606
|
---
|
606
607
|
|
607
|
-
When option `eslevel:
|
608
|
+
When option `eslevel: 2020` is provided, the following additional
|
608
609
|
conversion is made:
|
609
610
|
|
610
611
|
* `@x` becomes `this.#x`
|
@@ -50,9 +50,15 @@ module Ruby2JS
|
|
50
50
|
|
51
51
|
s(:send, s(:block, s(:send, nil, :lambda), s(:args),
|
52
52
|
s(:begin, *copy, *args.map {|modname|
|
53
|
-
|
54
|
-
|
55
|
-
|
53
|
+
if modname.type == :hash
|
54
|
+
s(:begin, *modname.children.map {|pair|
|
55
|
+
s(:send, s(:gvar, :$$), :[]=, *pair.children)
|
56
|
+
})
|
57
|
+
else
|
58
|
+
s(:for, s(:lvasgn, :$_), modname,
|
59
|
+
s(:send, s(:gvar, :$$), :[]=,
|
60
|
+
s(:lvar, :$_), s(:send, modname, :[], s(:lvar, :$_))))
|
61
|
+
end
|
56
62
|
}, s(:return, s(:gvar, :$$)))), :[])
|
57
63
|
end
|
58
64
|
|
@@ -72,9 +78,15 @@ module Ruby2JS
|
|
72
78
|
|
73
79
|
s(:send, s(:block, s(:send, nil, :lambda), s(:args),
|
74
80
|
s(:begin, *copy, *args.map {|modname|
|
75
|
-
|
76
|
-
|
77
|
-
|
81
|
+
if modname.type == :hash
|
82
|
+
s(:begin, *modname.children.map {|pair|
|
83
|
+
s(:send, target, :[]=, *pair.children)
|
84
|
+
})
|
85
|
+
else
|
86
|
+
s(:for, s(:lvasgn, :$_), modname,
|
87
|
+
s(:send, target, :[]=,
|
88
|
+
s(:lvar, :$_), s(:send, modname, :[], s(:lvar, :$_))))
|
89
|
+
end
|
78
90
|
}, s(:return, target))), :[])
|
79
91
|
end
|
80
92
|
|
@@ -522,13 +534,24 @@ module Ruby2JS
|
|
522
534
|
call.children[0].children[0], node.children[2])
|
523
535
|
|
524
536
|
elsif
|
525
|
-
[:each, :each_value].include? method
|
526
|
-
node.children[1].children.length == 1
|
537
|
+
[:each, :each_value].include? method
|
527
538
|
then
|
528
539
|
if es2015
|
529
|
-
|
530
|
-
|
531
|
-
|
540
|
+
if node.children[1].children.length > 1
|
541
|
+
process node.updated(:for_of,
|
542
|
+
[s(:mlhs, *node.children[1].children.map {|child|
|
543
|
+
s(:lvasgn, child.children[0])}),
|
544
|
+
node.children[0].children[0], node.children[2]])
|
545
|
+
elsif node.children[1].children[0].type == :mlhs
|
546
|
+
process node.updated(:for_of,
|
547
|
+
[s(:mlhs, *node.children[1].children[0].children.map {|child|
|
548
|
+
s(:lvasgn, child.children[0])}),
|
549
|
+
node.children[0].children[0], node.children[2]])
|
550
|
+
else
|
551
|
+
process node.updated(:for_of,
|
552
|
+
[s(:lvasgn, node.children[1].children[0].children[0]),
|
553
|
+
node.children[0].children[0], node.children[2]])
|
554
|
+
end
|
532
555
|
else
|
533
556
|
process node.updated(nil, [s(:send, call.children[0],
|
534
557
|
:forEach), *node.children[1..2]])
|
@@ -548,10 +571,21 @@ module Ruby2JS
|
|
548
571
|
s(:block, s(:send, nil, :lambda), *node.children[1..2]),
|
549
572
|
*call.children[2..-1]])
|
550
573
|
|
551
|
-
elsif
|
552
|
-
|
553
|
-
|
554
|
-
|
574
|
+
elsif method == :each_pair and node.children[1].children.length == 2
|
575
|
+
if es2017
|
576
|
+
# Object.entries(a).forEach(([key, value]) => {})
|
577
|
+
process node.updated(nil, [s(:send, s(:send,
|
578
|
+
s(:const, nil, :Object), :entries, call.children[0]), :each),
|
579
|
+
node.children[1], node.children[2]])
|
580
|
+
else
|
581
|
+
# for (key in a). {var value = a[key]; ...}
|
582
|
+
process node.updated(:for, [s(:lvasgn,
|
583
|
+
node.children[1].children[0].children[0]), call.children[0],
|
584
|
+
s(:begin, s(:lvasgn, node.children[1].children[1].children[0],
|
585
|
+
s(:send, call.children[0], :[],
|
586
|
+
s(:lvar, node.children[1].children[0].children[0]))),
|
587
|
+
node.children[2])])
|
588
|
+
end
|
555
589
|
|
556
590
|
else
|
557
591
|
super
|
data/lib/ruby2js/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby2js
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Ruby
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -140,8 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
140
|
- !ruby/object:Gem::Version
|
141
141
|
version: '0'
|
142
142
|
requirements: []
|
143
|
-
|
144
|
-
rubygems_version: 2.7.6
|
143
|
+
rubygems_version: 3.0.6
|
145
144
|
signing_key:
|
146
145
|
specification_version: 4
|
147
146
|
summary: Minimal yet extensible Ruby to JavaScript conversion.
|