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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7bde5c5bd57b0599c6d259986d4b3ccfe3ca2a055d6d11c80730666ca4172860
4
- data.tar.gz: e45ed225f7a1826de460f0a6370ff525465e138fe5c7feb5d8881dcb243a8ff0
3
+ metadata.gz: c2414f75bafbcf153ced6b3834b19513f4589d0745ca508eb2169fdc6c190c2f
4
+ data.tar.gz: b8847a24e1b7f96a5602c84034623c2f3847c17458b521d949fcbd5b9cb9c2b8
5
5
  SHA512:
6
- metadata.gz: b44e98bc72e235b40a53745027ed24abba5eff043ccc0923014284301ef65210a34c043878aa35d86f8234c7246e119c92f8f21ac10ec175dbd932aaa8ee7cae
7
- data.tar.gz: 743fd931691369c969df41a88cc19fa4a7bdf465afede108bce34fbfeddfa6ef74583aea260031f38ceb4aea37fecbfa4ca0cda95f48bcb6cd15d8c1dc95b3c4
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 `for (i in ...) {}`
224
- * `.each_key` becomes `Object.keys().forEach`
225
- * `.each_value` becomes `for (i in ...) {}`
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
- * `.each_key` becomes `for (i of ...) {}`
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
- * `.each_entry` becomes `Object.entries().forEach`
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: 2018` is provided, the following additional
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: 2018` is provided, the following additional
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
- s(:for, s(:lvasgn, :$_), modname,
54
- s(:send, s(:gvar, :$$), :[]=,
55
- s(:lvar, :$_), s(:send, modname, :[], s(:lvar, :$_))))
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
- s(:for, s(:lvasgn, :$_), modname,
76
- s(:send, target, :[]=,
77
- s(:lvar, :$_), s(:send, modname, :[], s(:lvar, :$_))))
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 and
526
- node.children[1].children.length == 1
537
+ [:each, :each_value].include? method
527
538
  then
528
539
  if es2015
529
- process node.updated(:for_of,
530
- [s(:lvasgn, node.children[1].children[0].children[0]),
531
- node.children[0].children[0], node.children[2]])
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 es2017 and method == :each_pair
552
- process node.updated(nil, [s(:send, s(:send, s(:const, nil, :Object),
553
- :entries, call.children[0]), :forEach), s(:args, s(:mlhs,
554
- *node.children[1].children)), node.children[2]])
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
@@ -1,8 +1,8 @@
1
1
  module Ruby2JS
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 3
4
- MINOR = 1
5
- TINY = 2
4
+ MINOR = 2
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
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.1.2
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-06-07 00:00:00.000000000 Z
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
- rubyforge_project:
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.