ruby2js 3.0.13 → 3.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/ruby2js/converter/class2.rb +10 -4
- data/lib/ruby2js/converter/regexp.rb +6 -0
- data/lib/ruby2js/converter/send.rb +4 -1
- data/lib/ruby2js/filter/functions.rb +42 -32
- data/lib/ruby2js/version.rb +1 -1
- 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: 977a5000855a15e2bb92f1c4c8c1ccea4fdf5ab3e7191119822baef7eae542c6
|
|
4
|
+
data.tar.gz: d37e1f93e78f0fb2ea11bb507764df75fc24e16146b173a5c9bf93819277911e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: daf2acb19662ed955b502f226fdf9f36226968926a3a6e17a2b4d180a8d89edbfc451464ee4ce24139c1f960de348521958147701cfa99248d1a80e6c5f51be6
|
|
7
|
+
data.tar.gz: 61d107547afd6f57ed4a98277c78e9edb86253bc61d6036520f22cd208d213f5c3a7ac010a738c94848bbdb649f608322379953a9892c92f4275f3d29181c068
|
data/README.md
CHANGED
|
@@ -34,6 +34,16 @@ module Ruby2JS
|
|
|
34
34
|
class_parent, @class_parent = @class_parent, inheritance
|
|
35
35
|
@rbstack.push({})
|
|
36
36
|
|
|
37
|
+
# capture method names for automatic self referencing
|
|
38
|
+
body.each_with_index do |m, index|
|
|
39
|
+
if m.type == :def
|
|
40
|
+
prop = m.children.first
|
|
41
|
+
unless prop == :initialize or prop.to_s.end_with? '='
|
|
42
|
+
@rbstack.last[prop] = s(:self)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
37
47
|
post = []
|
|
38
48
|
skipped = false
|
|
39
49
|
body.each_with_index do |m, index|
|
|
@@ -59,20 +69,16 @@ module Ruby2JS
|
|
|
59
69
|
@prop = :constructor
|
|
60
70
|
m = m.updated(m.type, [@prop, *m.children[1..2]])
|
|
61
71
|
elsif not m.is_method?
|
|
62
|
-
@rbstack.last[@prop] = s(:self)
|
|
63
72
|
@prop = "get #{@prop}"
|
|
64
73
|
m = m.updated(m.type, [*m.children[0..1],
|
|
65
74
|
s(:autoreturn, m.children[2])])
|
|
66
75
|
elsif @prop.to_s.end_with? '='
|
|
67
76
|
@prop = @prop.to_s.sub('=', '').to_sym
|
|
68
|
-
@rbstack.last[@prop] = s(:self)
|
|
69
77
|
m = m.updated(m.type, [@prop, *m.children[1..2]])
|
|
70
78
|
@prop = "set #{@prop}"
|
|
71
79
|
elsif @prop.to_s.end_with? '!'
|
|
72
80
|
@prop = @prop.to_s.sub('!', '')
|
|
73
81
|
m = m.updated(m.type, [@prop, *m.children[1..2]])
|
|
74
|
-
else
|
|
75
|
-
@rbstack.last[@prop] = s(:self)
|
|
76
82
|
end
|
|
77
83
|
|
|
78
84
|
begin
|
|
@@ -27,6 +27,12 @@ module Ruby2JS
|
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
+
if parts.first.type == :str and parts.first.children[0].start_with?('^')
|
|
31
|
+
opts = opts + [:m] unless opts.include? :m
|
|
32
|
+
elsif parts.last.type == :str and parts.last.children[0].end_with?('$')
|
|
33
|
+
opts = opts + [:m] unless opts.include? :m
|
|
34
|
+
end
|
|
35
|
+
|
|
30
36
|
# use slash syntax if there are few embedded slashes in the regexp
|
|
31
37
|
if parts.all? {|part| part.type == :str}
|
|
32
38
|
str = parts.map {|part| part.children.first}.join
|
|
@@ -111,6 +111,9 @@ module Ruby2JS
|
|
|
111
111
|
if receiver.type == :int and !OPERATORS.flatten.include?(method)
|
|
112
112
|
group_receiver = true
|
|
113
113
|
end
|
|
114
|
+
if not receiver.is_method? and receiver.children.last == :new
|
|
115
|
+
group_receiver = true
|
|
116
|
+
end
|
|
114
117
|
end
|
|
115
118
|
|
|
116
119
|
if target
|
|
@@ -221,7 +224,7 @@ module Ruby2JS
|
|
|
221
224
|
end
|
|
222
225
|
end
|
|
223
226
|
|
|
224
|
-
put "new ";
|
|
227
|
+
put "new "; (group_receiver ? group(receiver) : parse(receiver))
|
|
225
228
|
if ast.is_method?
|
|
226
229
|
put '('; parse_all(*args, join: ', '); put ')'
|
|
227
230
|
end
|
|
@@ -29,7 +29,7 @@ module Ruby2JS
|
|
|
29
29
|
*args)
|
|
30
30
|
|
|
31
31
|
elsif method == :call and target and target.type == :cvar
|
|
32
|
-
process S(:send, s(:attr, s(:self), :constructor),
|
|
32
|
+
process S(:send, s(:attr, s(:self), :constructor),
|
|
33
33
|
"_#{target.children.first.to_s[2..-1]}", *args)
|
|
34
34
|
|
|
35
35
|
elsif method == :keys and args.length == 0 and node.is_method?
|
|
@@ -73,7 +73,7 @@ module Ruby2JS
|
|
|
73
73
|
if es2015
|
|
74
74
|
process S(:send, s(:const, nil, :Array), :from, *args)
|
|
75
75
|
else
|
|
76
|
-
process S(:send, s(:attr, s(:attr, s(:const, nil, :Array),
|
|
76
|
+
process S(:send, s(:attr, s(:attr, s(:const, nil, :Array),
|
|
77
77
|
:prototype), :slice), :call, *args)
|
|
78
78
|
end
|
|
79
79
|
|
|
@@ -84,19 +84,22 @@ module Ruby2JS
|
|
|
84
84
|
process node.updated :send, [nil, :parseFloat, target, *args]
|
|
85
85
|
|
|
86
86
|
elsif method == :sub and args.length == 2
|
|
87
|
+
if args[1].type == :str
|
|
88
|
+
args[1] = s(:str, args[1].children.first.gsub(/\\(\d)/, "$\\1"))
|
|
89
|
+
end
|
|
87
90
|
process node.updated nil, [target, :replace, *args]
|
|
88
91
|
|
|
89
92
|
elsif [:sub!, :gsub!].include? method
|
|
90
93
|
method = :"#{method.to_s[0..-2]}"
|
|
91
94
|
if VAR_TO_ASSIGN.keys.include? target.type
|
|
92
|
-
process S(VAR_TO_ASSIGN[target.type], target.children[0],
|
|
95
|
+
process S(VAR_TO_ASSIGN[target.type], target.children[0],
|
|
93
96
|
S(:send, target, method, *node.children[2..-1]))
|
|
94
97
|
elsif target.type == :send
|
|
95
98
|
if target.children[0] == nil
|
|
96
99
|
process S(:lvasgn, target.children[1], S(:send,
|
|
97
100
|
S(:lvar, target.children[1]), method, *node.children[2..-1]))
|
|
98
101
|
else
|
|
99
|
-
process S(:send, target.children[0], :"#{target.children[1]}=",
|
|
102
|
+
process S(:send, target.children[0], :"#{target.children[1]}=",
|
|
100
103
|
S(:send, target, method, *node.children[2..-1]))
|
|
101
104
|
end
|
|
102
105
|
else
|
|
@@ -119,7 +122,7 @@ module Ruby2JS
|
|
|
119
122
|
else
|
|
120
123
|
super
|
|
121
124
|
end
|
|
122
|
-
|
|
125
|
+
|
|
123
126
|
if pattern.include? '('
|
|
124
127
|
s(:block, s(:send,
|
|
125
128
|
s(:send, process(target), :match, gpattern), :map),
|
|
@@ -139,6 +142,9 @@ module Ruby2JS
|
|
|
139
142
|
before = before.updated(:regexp,
|
|
140
143
|
[s(:str, Regexp.escape(before.children.first)), s(:regopt, :g)])
|
|
141
144
|
end
|
|
145
|
+
if after.type == :str
|
|
146
|
+
after = s(:str, after.children.first.gsub(/\\(\d)/, "$\\1"))
|
|
147
|
+
end
|
|
142
148
|
process node.updated nil, [target, :replace, before, after]
|
|
143
149
|
|
|
144
150
|
elsif method == :ord and args.length == 0
|
|
@@ -176,10 +182,10 @@ module Ruby2JS
|
|
|
176
182
|
end
|
|
177
183
|
|
|
178
184
|
if method == :start_with?
|
|
179
|
-
process S(:send, S(:send, target, :substring, s(:int, 0),
|
|
185
|
+
process S(:send, S(:send, target, :substring, s(:int, 0),
|
|
180
186
|
length), :==, *args)
|
|
181
187
|
else
|
|
182
|
-
process S(:send, S(:send, target, :slice,
|
|
188
|
+
process S(:send, S(:send, target, :slice,
|
|
183
189
|
S(:send, length, :-@)), :==, *args)
|
|
184
190
|
end
|
|
185
191
|
end
|
|
@@ -203,8 +209,12 @@ module Ruby2JS
|
|
|
203
209
|
S(:and, s(:send, args.first, :>=, target.children.first),
|
|
204
210
|
s(:send, args.first, :<, target.children.last))
|
|
205
211
|
else
|
|
206
|
-
|
|
207
|
-
|
|
212
|
+
if es2016
|
|
213
|
+
process S(:send, target, :includes, args.first)
|
|
214
|
+
else
|
|
215
|
+
process S(:send, S(:send, target, :indexOf, args.first), :!=,
|
|
216
|
+
s(:int, -1))
|
|
217
|
+
end
|
|
208
218
|
end
|
|
209
219
|
|
|
210
220
|
elsif method == :respond_to? and args.length == 1
|
|
@@ -220,7 +230,7 @@ module Ruby2JS
|
|
|
220
230
|
process S(:send, target, :toUpperCase)
|
|
221
231
|
|
|
222
232
|
elsif method == :strip and args.length == 0
|
|
223
|
-
process
|
|
233
|
+
process s(:send, target, :trim)
|
|
224
234
|
|
|
225
235
|
elsif node.children[0..1] == [nil, :puts]
|
|
226
236
|
process S(:send, s(:attr, nil, :console), :log, *args)
|
|
@@ -251,7 +261,7 @@ module Ruby2JS
|
|
|
251
261
|
# resolve negative literal indexes
|
|
252
262
|
i = proc do |index|
|
|
253
263
|
if index.type == :int and index.children.first < 0
|
|
254
|
-
process S(:send, S(:attr, target, :length), :-,
|
|
264
|
+
process S(:send, S(:attr, target, :length), :-,
|
|
255
265
|
s(:int, -index.children.first))
|
|
256
266
|
else
|
|
257
267
|
index
|
|
@@ -264,7 +274,7 @@ module Ruby2JS
|
|
|
264
274
|
super
|
|
265
275
|
|
|
266
276
|
elsif index.type == :regexp
|
|
267
|
-
process S(:send,
|
|
277
|
+
process S(:send,
|
|
268
278
|
s(:or, S(:send, process(target), :match, index), s(:array)),
|
|
269
279
|
:[], args[1] || s(:int, 0))
|
|
270
280
|
|
|
@@ -302,11 +312,11 @@ module Ruby2JS
|
|
|
302
312
|
super
|
|
303
313
|
end
|
|
304
314
|
|
|
305
|
-
elsif method == :reverse! and node.is_method?
|
|
315
|
+
elsif method == :reverse! and node.is_method?
|
|
306
316
|
# input: a.reverse!
|
|
307
317
|
# output: a.splice(0, a.length, *a.reverse)
|
|
308
|
-
process S(:send, target, :splice, s(:int, 0),
|
|
309
|
-
s(:attr, target, :length), s(:splat, S(:send, target,
|
|
318
|
+
process S(:send, target, :splice, s(:int, 0),
|
|
319
|
+
s(:attr, target, :length), s(:splat, S(:send, target,
|
|
310
320
|
:reverse, *node.children[2..-1])))
|
|
311
321
|
|
|
312
322
|
elsif method == :each_with_index
|
|
@@ -331,7 +341,7 @@ module Ruby2JS
|
|
|
331
341
|
S(:send, s(:const, nil, :Array), :isArray, target)
|
|
332
342
|
elsif [:Arguments, :Boolean, :Date, :Error, :Function, :Number,
|
|
333
343
|
:Object, :RegExp, :String].include? parent
|
|
334
|
-
S(:send, s(:send, s(:attr, s(:attr, s(:const, nil, Object),
|
|
344
|
+
S(:send, s(:send, s(:attr, s(:attr, s(:const, nil, Object),
|
|
335
345
|
:prototype), :toString), :call, target), :===,
|
|
336
346
|
s(:str, "[object #{parent.to_s}]"))
|
|
337
347
|
else
|
|
@@ -415,7 +425,7 @@ module Ruby2JS
|
|
|
415
425
|
# output: a.splice(0, a.length, *a.map {expression})
|
|
416
426
|
method = (method == :map! ? :map : :select)
|
|
417
427
|
target = call.children.first
|
|
418
|
-
process call.updated(:send, [target, :splice, s(:splat, s(:send,
|
|
428
|
+
process call.updated(:send, [target, :splice, s(:splat, s(:send,
|
|
419
429
|
s(:array, s(:int, 0), s(:attr, target, :length)), :concat,
|
|
420
430
|
s(:block, s(:send, target, method, *call.children[2..-1]),
|
|
421
431
|
*node.children[1..-1])))])
|
|
@@ -432,11 +442,11 @@ module Ruby2JS
|
|
|
432
442
|
if result.children[0].type == :undef
|
|
433
443
|
call = result.children[0].children[0]
|
|
434
444
|
if call.type == :attr
|
|
435
|
-
call = call.updated(:send,
|
|
445
|
+
call = call.updated(:send,
|
|
436
446
|
[call.children[0], :delete, s(:str, call.children[1])])
|
|
437
447
|
result = result.updated(nil, [call, *result.children[1..-1]])
|
|
438
448
|
else
|
|
439
|
-
call = call.updated(nil,
|
|
449
|
+
call = call.updated(nil,
|
|
440
450
|
[call.children[0], :delete, *call.children[2..-1]])
|
|
441
451
|
result = result.updated(nil, [call, *result.children[1..-1]])
|
|
442
452
|
end
|
|
@@ -454,19 +464,19 @@ module Ruby2JS
|
|
|
454
464
|
call = call.updated(nil, [s(:begin, range), :step, s(:int, 1)])
|
|
455
465
|
process node.updated(nil, [call, *node.children[1..-1]])
|
|
456
466
|
|
|
457
|
-
elsif
|
|
467
|
+
elsif
|
|
458
468
|
method == :each and call.children[0].type == :send and
|
|
459
469
|
call.children[0].children[1] == :step
|
|
460
470
|
then
|
|
461
471
|
# i.step(j, n).each {|v| ...}
|
|
462
472
|
range = call.children[0]
|
|
463
473
|
step = range.children[3] || s(:int, 1)
|
|
464
|
-
call = call.updated(nil, [s(:begin,
|
|
474
|
+
call = call.updated(nil, [s(:begin,
|
|
465
475
|
s(:irange, range.children[0], range.children[2])),
|
|
466
476
|
:step, step])
|
|
467
477
|
process node.updated(nil, [call, *node.children[1..-1]])
|
|
468
478
|
|
|
469
|
-
elsif
|
|
479
|
+
elsif
|
|
470
480
|
# (a..b).each {|v| ...}
|
|
471
481
|
method == :each and
|
|
472
482
|
call.children[0].type == :begin and
|
|
@@ -474,28 +484,28 @@ module Ruby2JS
|
|
|
474
484
|
[:irange, :erange].include? call.children[0].children[0].type and
|
|
475
485
|
node.children[1].children.length == 1
|
|
476
486
|
then
|
|
477
|
-
s(:for, s(:lvasgn, node.children[1].children[0].children[0]),
|
|
487
|
+
s(:for, s(:lvasgn, node.children[1].children[0].children[0]),
|
|
478
488
|
call.children[0].children[0], node.children[2])
|
|
479
489
|
|
|
480
|
-
elsif
|
|
481
|
-
[:each, :each_value].include? method and
|
|
490
|
+
elsif
|
|
491
|
+
[:each, :each_value].include? method and
|
|
482
492
|
node.children[1].children.length == 1
|
|
483
493
|
then
|
|
484
494
|
if es2015
|
|
485
|
-
process node.updated(:for_of,
|
|
495
|
+
process node.updated(:for_of,
|
|
486
496
|
[s(:lvasgn, node.children[1].children[0].children[0]),
|
|
487
497
|
node.children[0].children[0], node.children[2]])
|
|
488
498
|
else
|
|
489
|
-
process node.updated(nil, [s(:send, call.children[0],
|
|
499
|
+
process node.updated(nil, [s(:send, call.children[0],
|
|
490
500
|
:forEach), *node.children[1..2]])
|
|
491
501
|
end
|
|
492
502
|
|
|
493
|
-
elsif
|
|
494
|
-
method == :each_key and
|
|
495
|
-
[:each, :each_key].include? method and
|
|
503
|
+
elsif
|
|
504
|
+
method == :each_key and
|
|
505
|
+
[:each, :each_key].include? method and
|
|
496
506
|
node.children[1].children.length == 1
|
|
497
507
|
then
|
|
498
|
-
process node.updated(:for,
|
|
508
|
+
process node.updated(:for,
|
|
499
509
|
[s(:lvasgn, node.children[1].children[0].children[0]),
|
|
500
510
|
node.children[0].children[0], node.children[2]])
|
|
501
511
|
|
|
@@ -519,7 +529,7 @@ module Ruby2JS
|
|
|
519
529
|
body.compact!
|
|
520
530
|
|
|
521
531
|
if inheritance == s(:const, nil, :Exception)
|
|
522
|
-
unless
|
|
532
|
+
unless
|
|
523
533
|
body.any? {|statement| statement.type == :def and
|
|
524
534
|
statement.children.first == :initialize}
|
|
525
535
|
then
|
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.0.
|
|
4
|
+
version: 3.0.14
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sam Ruby
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2019-04-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: parser
|