ruby2js 4.1.1 → 4.1.5
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/lib/ruby2js/converter.rb +1 -0
- data/lib/ruby2js/converter/def.rb +3 -1
- data/lib/ruby2js/converter/logical.rb +1 -1
- data/lib/ruby2js/converter/match.rb +7 -0
- data/lib/ruby2js/converter/send.rb +3 -3
- data/lib/ruby2js/filter/active_functions.rb +9 -1
- data/lib/ruby2js/filter/camelCase.rb +19 -2
- data/lib/ruby2js/filter/functions.rb +11 -3
- data/lib/ruby2js/filter/lit-element.rb +1 -1
- data/lib/ruby2js/filter/react.rb +7 -1
- data/lib/ruby2js/serializer.rb +41 -10
- data/lib/ruby2js/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 412d541e9884847f722555edd11a71ead4c2358632976bf32f530ca270eb539b
|
4
|
+
data.tar.gz: f32b8d14177ee0f08466abfbb4a96017e6dc8a4e5a2226476c77f26affa7f81d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4be8efc1eb9ec2f1de81f5c0236b6ea3c868522043e305cb0dfcac80e61b1e57e5639f77ad2a0a6aa44b7b5eb87842db5a7072f42ab25ad625474904d88e4b8
|
7
|
+
data.tar.gz: 6f8c9c91f1ca05f4363023ee588e356226dbafcf09235d5ab25c5ffaef564109a4c653673bbf8a6da1c0b3a231f84231f25089fdd0c0207e7ddd6c8d25dfd7d7
|
data/lib/ruby2js/converter.rb
CHANGED
@@ -359,6 +359,7 @@ require 'ruby2js/converter/kwbegin'
|
|
359
359
|
require 'ruby2js/converter/literal'
|
360
360
|
require 'ruby2js/converter/logical'
|
361
361
|
require 'ruby2js/converter/masgn'
|
362
|
+
require 'ruby2js/converter/match'
|
362
363
|
require 'ruby2js/converter/module'
|
363
364
|
require 'ruby2js/converter/next'
|
364
365
|
require 'ruby2js/converter/nil'
|
@@ -169,7 +169,9 @@ module Ruby2JS
|
|
169
169
|
put 'function'
|
170
170
|
end
|
171
171
|
|
172
|
-
put '('
|
172
|
+
put '('
|
173
|
+
parse s(:args, *args.children.select {|arg| arg.type != :shadowarg})
|
174
|
+
put ") {#{nl}"
|
173
175
|
|
174
176
|
next_token, @next_token = @next_token, :return
|
175
177
|
@block_depth += 1 if @block_depth
|
@@ -69,7 +69,7 @@ module Ruby2JS
|
|
69
69
|
left = rewrite(*left.children)
|
70
70
|
end
|
71
71
|
|
72
|
-
if right.type != :send
|
72
|
+
if right.type != :send or OPERATORS.flatten.include? right.children[1]
|
73
73
|
s(:and, left, right)
|
74
74
|
elsif conditionally_equals(left, right.children.first)
|
75
75
|
# a && a.b => a&.b
|
@@ -323,13 +323,13 @@ module Ruby2JS
|
|
323
323
|
put 'typeof '; parse args.first
|
324
324
|
|
325
325
|
elsif ast.children[1] == :is_a? and receiver and args.length == 1
|
326
|
-
parse receiver; put ' instanceof '; parse args.first
|
326
|
+
put '('; parse receiver; put ' instanceof '; parse args.first; put ')'
|
327
327
|
|
328
328
|
elsif ast.children[1] == :kind_of? and receiver and args.length == 1
|
329
|
-
parse receiver; put ' instanceof '; parse args.first
|
329
|
+
put '('; parse receiver; put ' instanceof '; parse args.first; put ')'
|
330
330
|
|
331
331
|
elsif ast.children[1] == :instance_of? and receiver and args.length == 1
|
332
|
-
parse s(:send, s(:attr, receiver, :constructor), :==, args.first)
|
332
|
+
put '('; parse s(:send, s(:attr, receiver, :constructor), :==, args.first); put ')'
|
333
333
|
|
334
334
|
else
|
335
335
|
if method == :bind and receiver&.type == :send
|
@@ -7,7 +7,6 @@ module Ruby2JS
|
|
7
7
|
|
8
8
|
def on_send(node)
|
9
9
|
target, method, *args = node.children
|
10
|
-
return super unless args.empty?
|
11
10
|
|
12
11
|
if es2015 and method == :blank?
|
13
12
|
create_or_update_import("blank$")
|
@@ -18,6 +17,15 @@ module Ruby2JS
|
|
18
17
|
elsif es2015 and method == :presence
|
19
18
|
create_or_update_import("presence$")
|
20
19
|
process node.updated :send, [nil, "presence$", target]
|
20
|
+
elsif es2015 and method == :chomp
|
21
|
+
create_or_update_import("chomp$")
|
22
|
+
process node.updated :send, [nil, "chomp$", target, *args]
|
23
|
+
elsif es2015 and method == :delete_prefix
|
24
|
+
create_or_update_import("deletePrefix$")
|
25
|
+
process node.updated :send, [nil, "deletePrefix$", target, *args]
|
26
|
+
elsif es2015 and method == :delete_suffix
|
27
|
+
create_or_update_import("deleteSuffix$")
|
28
|
+
process node.updated :send, [nil, "deleteSuffix$", target, *args]
|
21
29
|
else
|
22
30
|
super
|
23
31
|
end
|
@@ -14,6 +14,9 @@ module Ruby2JS
|
|
14
14
|
attr_reader
|
15
15
|
attr_writer
|
16
16
|
method_missing
|
17
|
+
is_a?
|
18
|
+
kind_of?
|
19
|
+
instance_of?
|
17
20
|
}
|
18
21
|
|
19
22
|
CAPS_EXCEPTIONS = {
|
@@ -28,6 +31,8 @@ module Ruby2JS
|
|
28
31
|
}
|
29
32
|
|
30
33
|
def camelCase(symbol)
|
34
|
+
return symbol if ALLOWLIST.include?(symbol.to_s)
|
35
|
+
|
31
36
|
should_symbolize = symbol.is_a?(Symbol)
|
32
37
|
symbol = symbol
|
33
38
|
.to_s
|
@@ -64,7 +69,7 @@ module Ruby2JS
|
|
64
69
|
def handle_generic_node(node, node_type)
|
65
70
|
return node if node.type != node_type
|
66
71
|
|
67
|
-
if node.children[0] =~ /_
|
72
|
+
if node.children[0] =~ /_.*[?!\w]$/ and !ALLOWLIST.include?(node.children[0].to_s)
|
68
73
|
S(node_type , camelCase(node.children[0]), *node.children[1..-1])
|
69
74
|
else
|
70
75
|
node
|
@@ -99,6 +104,10 @@ module Ruby2JS
|
|
99
104
|
handle_generic_node(super, :arg)
|
100
105
|
end
|
101
106
|
|
107
|
+
def on_kwarg(node)
|
108
|
+
handle_generic_node(super, :kwarg)
|
109
|
+
end
|
110
|
+
|
102
111
|
def on_lvasgn(node)
|
103
112
|
handle_generic_node(super, :lvasgn)
|
104
113
|
end
|
@@ -111,6 +120,14 @@ module Ruby2JS
|
|
111
120
|
handle_generic_node(super, :cvasgn)
|
112
121
|
end
|
113
122
|
|
123
|
+
def on_match_pattern(node)
|
124
|
+
handle_generic_node(super, :match_pattern)
|
125
|
+
end
|
126
|
+
|
127
|
+
def on_match_var(node)
|
128
|
+
handle_generic_node(super, :match_var)
|
129
|
+
end
|
130
|
+
|
114
131
|
def on_sym(node)
|
115
132
|
handle_generic_node(super, :sym)
|
116
133
|
end
|
@@ -119,7 +136,7 @@ module Ruby2JS
|
|
119
136
|
node = super
|
120
137
|
return node if node.type != :defs
|
121
138
|
|
122
|
-
if node.children[1] =~ /_
|
139
|
+
if node.children[1] =~ /_.*[?!\w]$/
|
123
140
|
S(:defs , node.children[0],
|
124
141
|
camelCase(node.children[1]), *node.children[2..-1])
|
125
142
|
else
|
@@ -341,7 +341,11 @@ module Ruby2JS
|
|
341
341
|
|
342
342
|
elsif method == :last
|
343
343
|
if node.children.length == 2
|
344
|
-
|
344
|
+
if es2022
|
345
|
+
process S(:send, target, :at, s(:int, -1))
|
346
|
+
else
|
347
|
+
process on_send S(:send, target, :[], s(:int, -1))
|
348
|
+
end
|
345
349
|
elsif node.children.length == 3
|
346
350
|
process S(:send, target, :slice,
|
347
351
|
s(:send, s(:attr, target, :length), :-, node.children[2]),
|
@@ -358,8 +362,12 @@ module Ruby2JS
|
|
358
362
|
# resolve negative literal indexes
|
359
363
|
i = proc do |index|
|
360
364
|
if index.type == :int and index.children.first < 0
|
361
|
-
|
362
|
-
|
365
|
+
if es2022
|
366
|
+
return process S(:send, target, :at, index)
|
367
|
+
else
|
368
|
+
process S(:send, S(:attr, target, :length), :-,
|
369
|
+
s(:int, -index.children.first))
|
370
|
+
end
|
363
371
|
else
|
364
372
|
index
|
365
373
|
end
|
data/lib/ruby2js/filter/react.rb
CHANGED
@@ -1492,7 +1492,13 @@ module Ruby2JS
|
|
1492
1492
|
source = Ruby2JS.jsx2_rb(source)
|
1493
1493
|
ast = Ruby2JS.parse(source).first
|
1494
1494
|
ast = s(:block, s(:send, nil, :_), s(:args), ast) if ast.type == :begin
|
1495
|
-
|
1495
|
+
|
1496
|
+
begin
|
1497
|
+
react, @react = @react, @react || :react
|
1498
|
+
process ast
|
1499
|
+
ensure
|
1500
|
+
@react = react
|
1501
|
+
end
|
1496
1502
|
end
|
1497
1503
|
end
|
1498
1504
|
|
data/lib/ruby2js/serializer.rb
CHANGED
@@ -300,22 +300,29 @@ module Ruby2JS
|
|
300
300
|
BASE64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
|
301
301
|
|
302
302
|
# https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit
|
303
|
+
# http://sokra.github.io/source-map-visualization/
|
303
304
|
def vlq(*mark)
|
304
|
-
if
|
305
|
-
|
306
|
-
@
|
305
|
+
if !@mark
|
306
|
+
diffs = mark
|
307
|
+
@mark = [0, 0, 0, 0, 0, 0]
|
308
|
+
else
|
309
|
+
if @mark[0] == mark[0]
|
310
|
+
return if @mark[4] == mark[4] and @mark[3] == mark[3]
|
311
|
+
@mappings += ',' unless @mappings == ''
|
312
|
+
end
|
313
|
+
|
314
|
+
diffs = mark.zip(@mark).map {|a,b| a-b}
|
307
315
|
end
|
308
316
|
|
309
317
|
while @mark[0] < mark[0]
|
310
318
|
@mappings += ';'
|
311
319
|
@mark[0] += 1
|
312
|
-
|
320
|
+
diffs[1] = mark[1]
|
313
321
|
end
|
314
322
|
|
315
|
-
|
316
|
-
@mark = mark
|
323
|
+
@mark[0...mark.length] = mark
|
317
324
|
|
318
|
-
diffs[1
|
325
|
+
diffs[1..-1].each do |diff|
|
319
326
|
if diff < 0
|
320
327
|
data = (-diff << 1) + 1
|
321
328
|
else
|
@@ -345,7 +352,8 @@ module Ruby2JS
|
|
345
352
|
|
346
353
|
@mappings = ''
|
347
354
|
sources = []
|
348
|
-
|
355
|
+
names = []
|
356
|
+
@mark = nil
|
349
357
|
|
350
358
|
@lines.each_with_index do |line, row|
|
351
359
|
col = line.indent
|
@@ -361,8 +369,30 @@ module Ruby2JS
|
|
361
369
|
sources << buffer
|
362
370
|
end
|
363
371
|
|
364
|
-
|
365
|
-
|
372
|
+
line = buffer.line_for_position(pos) - 1
|
373
|
+
column = buffer.column_for_position(pos)
|
374
|
+
|
375
|
+
name = nil
|
376
|
+
if %i{lvasgn lvar}.include? token.ast.type
|
377
|
+
name = token.ast.children.first
|
378
|
+
elsif %i{casgn const}.include? token.ast.type
|
379
|
+
if token.ast.children.first == nil
|
380
|
+
name = token.ast.children[1]
|
381
|
+
end
|
382
|
+
end
|
383
|
+
|
384
|
+
if name
|
385
|
+
index = names.find_index(name)
|
386
|
+
|
387
|
+
unless index
|
388
|
+
index = names.length
|
389
|
+
names << name
|
390
|
+
end
|
391
|
+
|
392
|
+
vlq row, col, source_index, line, column, index
|
393
|
+
else
|
394
|
+
vlq row, col, source_index, line, column
|
395
|
+
end
|
366
396
|
end
|
367
397
|
col += token.length
|
368
398
|
end
|
@@ -372,6 +402,7 @@ module Ruby2JS
|
|
372
402
|
version: 3,
|
373
403
|
file: @file_name,
|
374
404
|
sources: sources.map(&:name),
|
405
|
+
names: names.map(&:to_s),
|
375
406
|
mappings: @mappings
|
376
407
|
}
|
377
408
|
end
|
data/lib/ruby2js/version.rb
CHANGED
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.1.
|
4
|
+
version: 4.1.5
|
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-08-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: parser
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- lib/ruby2js/converter/literal.rb
|
86
86
|
- lib/ruby2js/converter/logical.rb
|
87
87
|
- lib/ruby2js/converter/masgn.rb
|
88
|
+
- lib/ruby2js/converter/match.rb
|
88
89
|
- lib/ruby2js/converter/module.rb
|
89
90
|
- lib/ruby2js/converter/next.rb
|
90
91
|
- lib/ruby2js/converter/nil.rb
|