ruby2js 3.3.5 → 3.5.2
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 +99 -65
- data/lib/ruby2js.rb +22 -0
- data/lib/ruby2js/converter.rb +9 -4
- data/lib/ruby2js/converter/block.rb +5 -0
- data/lib/ruby2js/converter/class2.rb +9 -3
- data/lib/ruby2js/converter/cvar.rb +1 -1
- data/lib/ruby2js/converter/cvasgn.rb +1 -1
- data/lib/ruby2js/converter/def.rb +16 -0
- data/lib/ruby2js/converter/dstr.rb +1 -1
- data/lib/ruby2js/converter/hash.rb +3 -1
- data/lib/ruby2js/converter/import.rb +94 -10
- data/lib/ruby2js/converter/ivar.rb +13 -5
- data/lib/ruby2js/converter/ivasgn.rb +1 -1
- data/lib/ruby2js/converter/logical.rb +1 -1
- data/lib/ruby2js/converter/return.rb +3 -1
- data/lib/ruby2js/converter/taglit.rb +13 -0
- data/lib/ruby2js/converter/yield.rb +12 -0
- data/lib/ruby2js/filter/camelCase.rb +78 -35
- data/lib/ruby2js/filter/esm.rb +70 -41
- data/lib/ruby2js/filter/esm_migration.rb +72 -0
- data/lib/ruby2js/filter/fast-deep-equal.rb +23 -0
- data/lib/ruby2js/filter/functions.rb +24 -1
- data/lib/ruby2js/filter/node.rb +37 -53
- data/lib/ruby2js/filter/nokogiri.rb +3 -25
- data/lib/ruby2js/filter/require.rb +0 -2
- data/lib/ruby2js/filter/return.rb +9 -3
- data/lib/ruby2js/filter/securerandom.rb +33 -0
- data/lib/ruby2js/filter/tagged_templates.rb +40 -0
- data/lib/ruby2js/filter/vue.rb +9 -0
- data/lib/ruby2js/serializer.rb +1 -1
- data/lib/ruby2js/version.rb +2 -2
- data/ruby2js.gemspec +1 -1
- metadata +9 -4
- data/lib/ruby2js/filter/rubyjs.rb +0 -112
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'ruby2js'
|
2
|
+
require 'set'
|
3
|
+
|
4
|
+
# Experimental secure random support
|
5
|
+
|
6
|
+
module Ruby2JS
|
7
|
+
module Filter
|
8
|
+
module SecureRandom
|
9
|
+
include SEXP
|
10
|
+
extend SEXP
|
11
|
+
|
12
|
+
IMPORT_BASE62_RANDOM = s(:import, ['base62-random'],
|
13
|
+
s(:attr, nil, :base62_random))
|
14
|
+
|
15
|
+
def on_send(node)
|
16
|
+
target, method, *args = node.children
|
17
|
+
|
18
|
+
if target == s(:const, nil, :SecureRandom)
|
19
|
+
if method == :alphanumeric and args.length == 1
|
20
|
+
prepend_list << IMPORT_BASE62_RANDOM
|
21
|
+
node.updated(nil, [nil, :base62_random, *args])
|
22
|
+
else
|
23
|
+
super
|
24
|
+
end
|
25
|
+
else
|
26
|
+
super
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
DEFAULTS.push SecureRandom
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'ruby2js'
|
2
|
+
|
3
|
+
module Ruby2JS
|
4
|
+
module Filter
|
5
|
+
module TaggedTemplates
|
6
|
+
include SEXP
|
7
|
+
|
8
|
+
def initialize(*args)
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
def on_send(node)
|
13
|
+
target, method, *args = node.children
|
14
|
+
return super unless target.nil? and es2015
|
15
|
+
|
16
|
+
tagged_methods = @options[:template_literal_tags] || [:html, :css]
|
17
|
+
|
18
|
+
if tagged_methods.include?(method) && !args.empty?
|
19
|
+
strnode = process args.first
|
20
|
+
if strnode.type == :str
|
21
|
+
# convert regular strings to literal strings
|
22
|
+
strnode = strnode.updated(:dstr, [s(:str, strnode.children.first.chomp("\n"))])
|
23
|
+
else
|
24
|
+
# for literal strings, chomp a newline off the end
|
25
|
+
if strnode.children.last.type == :str && strnode.children.last.children[0].end_with?("\n")
|
26
|
+
children = [*strnode.children.take(strnode.children.length - 1), s(:str, strnode.children.last.children[0].chomp)]
|
27
|
+
strnode = s(:dstr, *children)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
S(:taglit, s(:sym, method), strnode)
|
32
|
+
else
|
33
|
+
super
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
DEFAULTS.push TaggedTemplates
|
39
|
+
end
|
40
|
+
end
|
data/lib/ruby2js/filter/vue.rb
CHANGED
@@ -106,6 +106,7 @@ module Ruby2JS
|
|
106
106
|
computed = []
|
107
107
|
setters = []
|
108
108
|
options = []
|
109
|
+
watch = nil
|
109
110
|
el = nil
|
110
111
|
mixins = []
|
111
112
|
|
@@ -205,6 +206,9 @@ module Ruby2JS
|
|
205
206
|
end
|
206
207
|
|
207
208
|
@vue_h = args.children.first.children.last
|
209
|
+
elsif method == :watch and args.children.length == 0 and block.type == :hash
|
210
|
+
watch = process(block)
|
211
|
+
next
|
208
212
|
elsif method == :initialize
|
209
213
|
method = :data
|
210
214
|
|
@@ -332,6 +336,11 @@ module Ruby2JS
|
|
332
336
|
hash << s(:pair, s(:sym, :computed), s(:hash, *computed))
|
333
337
|
end
|
334
338
|
|
339
|
+
# append watch to hash
|
340
|
+
if watch
|
341
|
+
hash << s(:pair, s(:sym, :watch), watch)
|
342
|
+
end
|
343
|
+
|
335
344
|
# convert class name to camel case
|
336
345
|
cname = cname.children.last
|
337
346
|
camel = cname.to_s.gsub(/[^\w]/, '-').
|
data/lib/ruby2js/serializer.rb
CHANGED
@@ -355,7 +355,7 @@ module Ruby2JS
|
|
355
355
|
end
|
356
356
|
|
357
357
|
split = buffer.source[0...pos].split("\n")
|
358
|
-
vlq row, col, source_index, split.length-1, split.last.to_s.length
|
358
|
+
vlq row, col, source_index, [split.length - 1, 0].max, split.last.to_s.length
|
359
359
|
end
|
360
360
|
col += token.length
|
361
361
|
end
|
data/lib/ruby2js/version.rb
CHANGED
data/ruby2js.gemspec
CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.files = %w(ruby2js.gemspec README.md) + Dir.glob("{lib}/**/*")
|
16
16
|
s.homepage = "http://github.com/rubys/ruby2js".freeze
|
17
17
|
s.licenses = ["MIT".freeze]
|
18
|
-
s.required_ruby_version = Gem::Requirement.new(">= 2.
|
18
|
+
s.required_ruby_version = Gem::Requirement.new(">= 2.3".freeze)
|
19
19
|
s.summary = "Minimal yet extensible Ruby to JavaScript conversion.".freeze
|
20
20
|
|
21
21
|
s.add_dependency('parser')
|
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.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Ruby
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -94,6 +94,7 @@ files:
|
|
94
94
|
- lib/ruby2js/converter/send.rb
|
95
95
|
- lib/ruby2js/converter/super.rb
|
96
96
|
- lib/ruby2js/converter/sym.rb
|
97
|
+
- lib/ruby2js/converter/taglit.rb
|
97
98
|
- lib/ruby2js/converter/undef.rb
|
98
99
|
- lib/ruby2js/converter/until.rb
|
99
100
|
- lib/ruby2js/converter/untilpost.rb
|
@@ -103,6 +104,7 @@ files:
|
|
103
104
|
- lib/ruby2js/converter/whilepost.rb
|
104
105
|
- lib/ruby2js/converter/xnode.rb
|
105
106
|
- lib/ruby2js/converter/xstr.rb
|
107
|
+
- lib/ruby2js/converter/yield.rb
|
106
108
|
- lib/ruby2js/es2015.rb
|
107
109
|
- lib/ruby2js/es2015/strict.rb
|
108
110
|
- lib/ruby2js/es2016.rb
|
@@ -122,6 +124,8 @@ files:
|
|
122
124
|
- lib/ruby2js/filter/camelCase.rb
|
123
125
|
- lib/ruby2js/filter/cjs.rb
|
124
126
|
- lib/ruby2js/filter/esm.rb
|
127
|
+
- lib/ruby2js/filter/esm_migration.rb
|
128
|
+
- lib/ruby2js/filter/fast-deep-equal.rb
|
125
129
|
- lib/ruby2js/filter/functions.rb
|
126
130
|
- lib/ruby2js/filter/jquery.rb
|
127
131
|
- lib/ruby2js/filter/matchAll.rb
|
@@ -131,7 +135,8 @@ files:
|
|
131
135
|
- lib/ruby2js/filter/react.rb
|
132
136
|
- lib/ruby2js/filter/require.rb
|
133
137
|
- lib/ruby2js/filter/return.rb
|
134
|
-
- lib/ruby2js/filter/
|
138
|
+
- lib/ruby2js/filter/securerandom.rb
|
139
|
+
- lib/ruby2js/filter/tagged_templates.rb
|
135
140
|
- lib/ruby2js/filter/underscore.rb
|
136
141
|
- lib/ruby2js/filter/vue.rb
|
137
142
|
- lib/ruby2js/filter/wunderbar.rb
|
@@ -154,7 +159,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
154
159
|
requirements:
|
155
160
|
- - ">="
|
156
161
|
- !ruby/object:Gem::Version
|
157
|
-
version: '2.
|
162
|
+
version: '2.3'
|
158
163
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
164
|
requirements:
|
160
165
|
- - ">="
|
@@ -1,112 +0,0 @@
|
|
1
|
-
require 'ruby2js'
|
2
|
-
|
3
|
-
module Ruby2JS
|
4
|
-
module Filter
|
5
|
-
module RubyJS
|
6
|
-
include SEXP
|
7
|
-
|
8
|
-
def on_send(node)
|
9
|
-
# leave functional style calls alone
|
10
|
-
target = node.children.first
|
11
|
-
return super if target and [:_s, :_a, :_h, :_n, :_i, :_t].
|
12
|
-
include? target.children[1]
|
13
|
-
|
14
|
-
method = node.children[1]
|
15
|
-
return super if excluded?(method)
|
16
|
-
|
17
|
-
# leave classic ("OO") style call chains alone
|
18
|
-
while target and target.type == :send
|
19
|
-
return super if target.children[1] == :R
|
20
|
-
target = target.children.first
|
21
|
-
end
|
22
|
-
|
23
|
-
if \
|
24
|
-
[:capitalize, :center, :chomp, :ljust, :lstrip, :rindex, :rjust,
|
25
|
-
:rstrip, :scan, :swapcase, :tr].include? method
|
26
|
-
then
|
27
|
-
# map selected string functions
|
28
|
-
s(:send, s(:lvar, :_s), method,
|
29
|
-
*process_all([node.children[0], *node.children[2..-1]]))
|
30
|
-
|
31
|
-
elsif \
|
32
|
-
[:at, :compact, :compact!, :delete_at, :delete_at, :flatten, :insert,
|
33
|
-
:reverse, :reverse!, :rotate, :rotate, :rotate!, :shift, :shuffle,
|
34
|
-
:shuffle!, :slice, :slice!, :transpose, :union, :uniq, :uniq!]
|
35
|
-
.include? method
|
36
|
-
then
|
37
|
-
# map selected array functions
|
38
|
-
s(:send, s(:lvar, :_a), method.to_s.sub("!", '_bang'),
|
39
|
-
*process_all([node.children[0], *node.children[2..-1]]))
|
40
|
-
|
41
|
-
|
42
|
-
elsif [:strftime].include? method
|
43
|
-
# map selected time functions
|
44
|
-
s(:send, s(:lvar, :_t), method,
|
45
|
-
*process_all([node.children[0], *node.children[2..-1]]))
|
46
|
-
|
47
|
-
elsif method == :<=>
|
48
|
-
s(:send, s(:attr, s(:const, nil, :R), :Comparable), :cmp,
|
49
|
-
node.children[0], *node.children[2..-1])
|
50
|
-
|
51
|
-
elsif method == :between?
|
52
|
-
s(:send, s(:send, nil, :R, node.children[0]), :between,
|
53
|
-
*node.children[2..-1])
|
54
|
-
|
55
|
-
else
|
56
|
-
super
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def on_block(node)
|
61
|
-
call, args, *block = node.children
|
62
|
-
method = call.children[1]
|
63
|
-
return super if excluded?(method)
|
64
|
-
|
65
|
-
if \
|
66
|
-
[:collect_concat, :count, :cycle, :delete_if, :drop_while,
|
67
|
-
:each_index, :each_slice, :each_with_index, :each_with_object,
|
68
|
-
:find, :find_all, :flat_map, :inject, :grep, :group_by, :keep_if,
|
69
|
-
:map, :max_by, :min_by, :one?, :partition, :reject, :reverse_each,
|
70
|
-
:select!, :sort_by, :take_while].include? method
|
71
|
-
then
|
72
|
-
if \
|
73
|
-
[:collect_concat, :count, :delete_if, :drop_while, :find,
|
74
|
-
:find_all, :flat_map, :grep, :group_by, :keep_if, :map, :max_by,
|
75
|
-
:min_by, :one?, :partition, :reject, :select!, :sort_by,
|
76
|
-
:take_while].include? method
|
77
|
-
then
|
78
|
-
block = [ s(:autoreturn, *block) ]
|
79
|
-
end
|
80
|
-
|
81
|
-
lvar = [:each_index, :keep_if, :select!].include?(method) ? :_a : :_e
|
82
|
-
|
83
|
-
if method == :find and call.children.length == 2
|
84
|
-
call = s(:send, *call.children, s(:nil))
|
85
|
-
elsif method == :inject and call.children.length == 3
|
86
|
-
call = s(:send, *call.children, s(:nil))
|
87
|
-
elsif method == :select!
|
88
|
-
call = s(:send, call.children.first, :select_bang,
|
89
|
-
*call.children[2..-1])
|
90
|
-
end
|
91
|
-
|
92
|
-
s(:block, s(:send, s(:lvar, lvar), call.children[1],
|
93
|
-
*process_all([call.children[0], *call.children[2..-1]])),
|
94
|
-
args, *block)
|
95
|
-
else
|
96
|
-
super
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
def on_irange(node)
|
101
|
-
s(:send, s(:attr, s(:const, nil, :R), :Range), :new, *node.children)
|
102
|
-
end
|
103
|
-
|
104
|
-
def on_erange(node)
|
105
|
-
s(:send, s(:attr, s(:const, nil, :R), :Range), :new, *node.children,
|
106
|
-
s(:true))
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
DEFAULTS.push RubyJS
|
111
|
-
end
|
112
|
-
end
|