ruby2js 3.5.1 → 3.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/lib/ruby2js.rb +19 -0
- data/lib/ruby2js/converter.rb +1 -1
- data/lib/ruby2js/converter/import.rb +16 -0
- data/lib/ruby2js/filter/esm.rb +34 -0
- data/lib/ruby2js/filter/functions.rb +9 -0
- data/lib/ruby2js/filter/node.rb +37 -60
- data/lib/ruby2js/filter/nokogiri.rb +3 -29
- data/lib/ruby2js/filter/return.rb +2 -0
- data/lib/ruby2js/filter/securerandom.rb +33 -0
- data/lib/ruby2js/filter/vue.rb +9 -0
- 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: 8995ca731fa2bedb5306084bca13f70aa01c269a3b3ac9b6c0ace540a0d58fae
|
4
|
+
data.tar.gz: 71c6cbb010ddf18f67623307c469f1ce4f55c4938c33a9e3172161f71819de87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b51e4838e7180248ffb00debab0758049dcc6a989bcc4b9e1087fb7112ac1a8142507c96e21309b23c3b69d987065e9d7fafb91dd0a7d8961b25f125fafc3788
|
7
|
+
data.tar.gz: fe7b943fc51b4f1685b5cc7020c969101d7a9aa17834bc6a8af746fdbe9472f9cc55960ef464f8dcfc10125598d6966a8cf38322ce432ec88e6dd787a49158ac
|
data/README.md
CHANGED
@@ -243,8 +243,10 @@ the script.
|
|
243
243
|
|
244
244
|
* <a id="functions" href="https://github.com/rubys/ruby2js/blob/master/lib/ruby2js/filter/functions.rb">functions</a>
|
245
245
|
|
246
|
+
* `.abs` becomes `Math.abs()`
|
246
247
|
* `.all?` becomes `.every`
|
247
248
|
* `.any?` becomes `.some`
|
249
|
+
* `.ceil` becomes `Math.ceil()`
|
248
250
|
* `.chr` becomes `fromCharCode`
|
249
251
|
* `.clear` becomes `.length = 0`
|
250
252
|
* `.delete` becomes `delete target[arg]`
|
@@ -259,6 +261,7 @@ the script.
|
|
259
261
|
* `.find_index` becomes `findIndex`
|
260
262
|
* `.first` becomes `[0]`
|
261
263
|
* `.first(n)` becomes `.slice(0, n)`
|
264
|
+
* `.floor` becomes `Math.floor()`
|
262
265
|
* `.gsub` becomes `replace(//g)`
|
263
266
|
* `.include?` becomes `.indexOf() != -1`
|
264
267
|
* `.inspect` becomes `JSON.stringify()`
|
data/lib/ruby2js.rb
CHANGED
@@ -17,6 +17,7 @@ module Ruby2JS
|
|
17
17
|
|
18
18
|
@@eslevel_default = 2009 # ecmascript 5
|
19
19
|
@@strict_default = false
|
20
|
+
@@module_default = nil
|
20
21
|
|
21
22
|
def self.eslevel_default
|
22
23
|
@@eslevel_default
|
@@ -34,6 +35,14 @@ module Ruby2JS
|
|
34
35
|
@@strict_default = level
|
35
36
|
end
|
36
37
|
|
38
|
+
def self.module_default
|
39
|
+
@@module_default
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.module_default=(module_type)
|
43
|
+
@@module_default = module_type
|
44
|
+
end
|
45
|
+
|
37
46
|
module Filter
|
38
47
|
DEFAULTS = []
|
39
48
|
|
@@ -52,11 +61,14 @@ module Ruby2JS
|
|
52
61
|
include Ruby2JS::Filter
|
53
62
|
BINARY_OPERATORS = Converter::OPERATORS[2..-1].flatten
|
54
63
|
|
64
|
+
attr_accessor :prepend_list
|
65
|
+
|
55
66
|
def initialize(comments)
|
56
67
|
@comments = comments
|
57
68
|
@ast = nil
|
58
69
|
@exclude_methods = []
|
59
70
|
@esm = false
|
71
|
+
@prepend_list = Set.new
|
60
72
|
end
|
61
73
|
|
62
74
|
def options=(options)
|
@@ -162,6 +174,7 @@ module Ruby2JS
|
|
162
174
|
def self.convert(source, options={})
|
163
175
|
options[:eslevel] ||= @@eslevel_default
|
164
176
|
options[:strict] = @@strict_default if options[:strict] == nil
|
177
|
+
options[:module] ||= @@module_default || :esm
|
165
178
|
|
166
179
|
if Proc === source
|
167
180
|
file,line = source.source_location
|
@@ -193,6 +206,11 @@ module Ruby2JS
|
|
193
206
|
|
194
207
|
filter.options = options
|
195
208
|
ast = filter.process(ast)
|
209
|
+
|
210
|
+
if filter.prepend_list
|
211
|
+
prepend = filter.prepend_list.sort_by {|ast| ast.type == :import ? 0 : 1}
|
212
|
+
ast = Parser::AST::Node.new(:begin, [*prepend, ast])
|
213
|
+
end
|
196
214
|
end
|
197
215
|
|
198
216
|
ruby2js = Ruby2JS::Converter.new(ast, comments)
|
@@ -203,6 +221,7 @@ module Ruby2JS
|
|
203
221
|
ruby2js.strict = options[:strict]
|
204
222
|
ruby2js.comparison = options[:comparison] || :equality
|
205
223
|
ruby2js.or = options[:or] || :logical
|
224
|
+
ruby2js.module_type = options[:module] || :esm
|
206
225
|
ruby2js.underscored_private = (options[:eslevel] < 2020) || options[:underscored_private]
|
207
226
|
if ruby2js.binding and not ruby2js.ivars
|
208
227
|
ruby2js.ivars = ruby2js.binding.eval \
|
data/lib/ruby2js/converter.rb
CHANGED
@@ -130,7 +130,7 @@ module Ruby2JS
|
|
130
130
|
Parser::AST::Node.new(type, args)
|
131
131
|
end
|
132
132
|
|
133
|
-
attr_accessor :strict, :eslevel, :comparison, :or, :underscored_private
|
133
|
+
attr_accessor :strict, :eslevel, :module_type, :comparison, :or, :underscored_private
|
134
134
|
|
135
135
|
def es2015
|
136
136
|
@eslevel >= 2015
|
@@ -6,7 +6,23 @@ module Ruby2JS
|
|
6
6
|
# NOTE: import is a synthetic
|
7
7
|
|
8
8
|
handle :import do |path, *args|
|
9
|
+
if module_type == :cjs
|
10
|
+
# only the subset of import syntaxes generated by filters are handled here
|
11
|
+
if Parser::AST::Node === args.first and args.first.type == :attr
|
12
|
+
return parse s(:casgn, *args.first.children,
|
13
|
+
s(:send, nil, :require, s(:str, Array(path).first))), :statement
|
14
|
+
elsif Array === args.first and args.first.length == 1
|
15
|
+
target = args.first.first
|
16
|
+
if Parser::AST::Node === target and target.type == :attr and target.children.first == nil
|
17
|
+
return parse s(:casgn, *target.children,
|
18
|
+
s(:attr, s(:send, nil, :require, s(:str, Array(path).first)), target.children.last)),
|
19
|
+
:statement
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
9
24
|
put 'import '
|
25
|
+
|
10
26
|
if args.length == 0
|
11
27
|
# import "file.css"
|
12
28
|
put path.inspect
|
data/lib/ruby2js/filter/esm.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'ruby2js'
|
2
2
|
|
3
|
+
Ruby2JS.module_default = :esm
|
4
|
+
|
3
5
|
module Ruby2JS
|
4
6
|
module Filter
|
5
7
|
module ESM
|
@@ -8,6 +10,27 @@ module Ruby2JS
|
|
8
10
|
def initialize(*args)
|
9
11
|
super
|
10
12
|
@esm = true # signal for other filters
|
13
|
+
@esm_imports = nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def options=(options)
|
17
|
+
super
|
18
|
+
@esm_autoimports = options[:autoimports]
|
19
|
+
return unless @esm_autoimports
|
20
|
+
end
|
21
|
+
|
22
|
+
def process(node)
|
23
|
+
return super if @esm_imports or not @esm_autoimports
|
24
|
+
@esm_imports = Set.new
|
25
|
+
result = super
|
26
|
+
|
27
|
+
if @esm_imports.empty?
|
28
|
+
result
|
29
|
+
else
|
30
|
+
s(:begin, *@esm_imports.to_a.map {|token|
|
31
|
+
s(:import, @esm_autoimports[token], s(:const, nil, token))
|
32
|
+
}, result)
|
33
|
+
end
|
11
34
|
end
|
12
35
|
|
13
36
|
def on_send(node)
|
@@ -56,10 +79,21 @@ module Ruby2JS
|
|
56
79
|
end
|
57
80
|
elsif method == :export
|
58
81
|
s(:export, *process_all(args))
|
82
|
+
elsif @esm_imports and args.length == 0 and @esm_autoimports[method]
|
83
|
+
@esm_imports.add(method)
|
84
|
+
super
|
59
85
|
else
|
60
86
|
super
|
61
87
|
end
|
62
88
|
end
|
89
|
+
|
90
|
+
def on_const(node)
|
91
|
+
return super unless @esm_autoimports
|
92
|
+
if node.children.first == nil and @esm_autoimports[node.children.last]
|
93
|
+
@esm_imports.add(node.children.last)
|
94
|
+
end
|
95
|
+
super
|
96
|
+
end
|
63
97
|
end
|
64
98
|
|
65
99
|
DEFAULTS.push ESM
|
@@ -531,6 +531,15 @@ module Ruby2JS
|
|
531
531
|
elsif method == :block_given? and target == nil and args.length == 0
|
532
532
|
process process s(:lvar, "_implicitBlockYield")
|
533
533
|
|
534
|
+
elsif method == :abs and args.length == 0
|
535
|
+
process S(:send, s(:const, nil, :Math), :abs, target)
|
536
|
+
|
537
|
+
elsif method == :ceil and args.length == 0
|
538
|
+
process S(:send, s(:const, nil, :Math), :ceil, target)
|
539
|
+
|
540
|
+
elsif method == :floor and args.length == 0
|
541
|
+
process S(:send, s(:const, nil, :Math), :floor, target)
|
542
|
+
|
534
543
|
else
|
535
544
|
super
|
536
545
|
end
|
data/lib/ruby2js/filter/node.rb
CHANGED
@@ -1,44 +1,21 @@
|
|
1
1
|
require 'ruby2js'
|
2
2
|
require 'set'
|
3
3
|
|
4
|
+
Ruby2JS.module_default ||= :cjs
|
5
|
+
|
4
6
|
module Ruby2JS
|
5
7
|
module Filter
|
6
8
|
module Node
|
7
9
|
include SEXP
|
8
10
|
extend SEXP
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
s(:send, nil, :require, s(:str, "child_process"))),
|
13
|
-
fs: s(:casgn, nil, :fs, s(:send, nil, :require, s(:str, "fs"))),
|
14
|
-
ARGV: s(:lvasgn, :ARGV, s(:send, s(:attr,
|
15
|
-
s(:attr, nil, :process), :argv), :slice, s(:int, 2)))
|
16
|
-
}
|
17
|
-
|
18
|
-
ESM_SETUP = {
|
19
|
-
child_process: s(:import, ['child_process'],
|
20
|
-
s(:attr, nil, :child_process)),
|
21
|
-
fs: s(:import, ['fs'], s(:attr, nil, :fs)),
|
22
|
-
ARGV: CJS_SETUP[:ARGV]
|
23
|
-
}
|
24
|
-
|
25
|
-
def initialize(*args)
|
26
|
-
@node_setup = nil
|
27
|
-
super
|
28
|
-
end
|
12
|
+
IMPORT_CHILD_PROCESS = s(:import, ['child_process'],
|
13
|
+
s(:attr, nil, :child_process))
|
29
14
|
|
30
|
-
|
31
|
-
return super if @node_setup
|
32
|
-
@node_setup = Set.new
|
33
|
-
result = super
|
15
|
+
IMPORT_FS = s(:import, ['fs'], s(:attr, nil, :fs))
|
34
16
|
|
35
|
-
|
36
|
-
|
37
|
-
else
|
38
|
-
setup = @esm ? ESM_SETUP : CJS_SETUP;
|
39
|
-
s(:begin, *@node_setup.to_a.map {|token| setup[token]}, result)
|
40
|
-
end
|
41
|
-
end
|
17
|
+
SETUP_ARGV = s(:lvasgn, :ARGV, s(:send, s(:attr,
|
18
|
+
s(:attr, nil, :process), :argv), :slice, s(:int, 2)))
|
42
19
|
|
43
20
|
def on_send(node)
|
44
21
|
target, method, *args = node.children
|
@@ -51,7 +28,7 @@ module Ruby2JS
|
|
51
28
|
s(:send, s(:attr, nil, :process), :exit, *process_all(args));
|
52
29
|
|
53
30
|
elsif method == :system
|
54
|
-
|
31
|
+
prepend_list << IMPORT_CHILD_PROCESS
|
55
32
|
|
56
33
|
if args.length == 1
|
57
34
|
s(:send, s(:attr, nil, :child_process), :execSync,
|
@@ -79,38 +56,38 @@ module Ruby2JS
|
|
79
56
|
target.type == :const and target.children.first == nil
|
80
57
|
then
|
81
58
|
if method == :read and args.length == 1
|
82
|
-
|
59
|
+
prepend_list << IMPORT_FS
|
83
60
|
s(:send, s(:attr, nil, :fs), :readFileSync, *process_all(args),
|
84
61
|
s(:str, 'utf8'))
|
85
62
|
|
86
63
|
elsif method == :write and args.length == 2
|
87
|
-
|
64
|
+
prepend_list << IMPORT_FS
|
88
65
|
S(:send, s(:attr, nil, :fs), :writeFileSync, *process_all(args))
|
89
66
|
|
90
67
|
elsif target.children.last == :IO
|
91
68
|
super
|
92
69
|
|
93
70
|
elsif [:exist?, :exists?].include? method and args.length == 1
|
94
|
-
|
71
|
+
prepend_list << IMPORT_FS
|
95
72
|
S(:send, s(:attr, nil, :fs), :existsSync, process(args.first))
|
96
73
|
|
97
74
|
elsif method == :readlink and args.length == 1
|
98
|
-
|
75
|
+
prepend_list << IMPORT_FS
|
99
76
|
S(:send, s(:attr, nil, :fs), :readlinkSync, process(args.first))
|
100
77
|
|
101
78
|
elsif method == :realpath and args.length == 1
|
102
|
-
|
79
|
+
prepend_list << IMPORT_FS
|
103
80
|
S(:send, s(:attr, nil, :fs), :realpathSync, process(args.first))
|
104
81
|
|
105
82
|
elsif method == :rename and args.length == 2
|
106
|
-
|
83
|
+
prepend_list << IMPORT_FS
|
107
84
|
S(:send, s(:attr, nil, :fs), :renameSync, *process_all(args))
|
108
85
|
|
109
86
|
elsif \
|
110
87
|
[:chmod, :lchmod].include? method and
|
111
88
|
args.length > 1 and args.first.type == :int
|
112
89
|
then
|
113
|
-
|
90
|
+
prepend_list << IMPORT_FS
|
114
91
|
|
115
92
|
S(:begin, *args[1..-1].map{|file|
|
116
93
|
S(:send, s(:attr, nil, :fs), method.to_s + 'Sync', process(file),
|
@@ -121,7 +98,7 @@ module Ruby2JS
|
|
121
98
|
[:chown, :lchown].include? method and args.length > 2 and
|
122
99
|
args[0].type == :int and args[1].type == :int
|
123
100
|
then
|
124
|
-
|
101
|
+
prepend_list << IMPORT_FS
|
125
102
|
|
126
103
|
S(:begin, *args[2..-1].map{|file|
|
127
104
|
s(:send, s(:attr, nil, :fs), method.to_s + 'Sync', process(file),
|
@@ -129,24 +106,24 @@ module Ruby2JS
|
|
129
106
|
})
|
130
107
|
|
131
108
|
elsif [:ln, :link].include? method and args.length == 2
|
132
|
-
|
109
|
+
prepend_list << IMPORT_FS
|
133
110
|
s(:send, s(:attr, nil, :fs), :linkSync, *process_all(args))
|
134
111
|
|
135
112
|
elsif method == :symlink and args.length == 2
|
136
|
-
|
113
|
+
prepend_list << IMPORT_FS
|
137
114
|
s(:send, s(:attr, nil, :fs), :symlinkSync, *process_all(args))
|
138
115
|
|
139
116
|
elsif method == :truncate and args.length == 2
|
140
|
-
|
117
|
+
prepend_list << IMPORT_FS
|
141
118
|
s(:send, s(:attr, nil, :fs), :truncateSync, *process_all(args))
|
142
119
|
|
143
120
|
elsif [:stat, :lstat].include? method and args.length == 1
|
144
|
-
|
121
|
+
prepend_list << IMPORT_FS
|
145
122
|
s(:send, s(:attr, nil, :fs), method.to_s + 'Sync',
|
146
123
|
process(args.first))
|
147
124
|
|
148
125
|
elsif method == :unlink and args.length == 1
|
149
|
-
|
126
|
+
prepend_list << IMPORT_FS
|
150
127
|
S(:begin, *args.map{|file|
|
151
128
|
S(:send, s(:attr, nil, :fs), :unlinkSync, process(file))
|
152
129
|
})
|
@@ -169,15 +146,15 @@ module Ruby2JS
|
|
169
146
|
end
|
170
147
|
|
171
148
|
if [:cp, :copy].include? method and args.length == 2
|
172
|
-
|
149
|
+
prepend_list << IMPORT_FS
|
173
150
|
s(:send, s(:attr, nil, :fs), :copyFileSync, *process_all(args))
|
174
151
|
|
175
152
|
elsif [:mv, :move].include? method and args.length == 2
|
176
|
-
|
153
|
+
prepend_list << IMPORT_FS
|
177
154
|
S(:send, s(:attr, nil, :fs), :renameSync, *process_all(args))
|
178
155
|
|
179
156
|
elsif method == :mkdir and args.length == 1
|
180
|
-
|
157
|
+
prepend_list << IMPORT_FS
|
181
158
|
S(:begin, *list[args.last].map {|file|
|
182
159
|
s(:send, s(:attr, nil, :fs), :mkdirSync, process(file))
|
183
160
|
})
|
@@ -189,21 +166,21 @@ module Ruby2JS
|
|
189
166
|
s(:send, s(:attr, nil, :process), :cwd)
|
190
167
|
|
191
168
|
elsif method == :rmdir and args.length == 1
|
192
|
-
|
169
|
+
prepend_list << IMPORT_FS
|
193
170
|
S(:begin, *list[args.last].map {|file|
|
194
171
|
s(:send, s(:attr, nil, :fs), :rmdirSync, process(file))
|
195
172
|
})
|
196
173
|
|
197
174
|
elsif method == :ln and args.length == 2
|
198
|
-
|
175
|
+
prepend_list << IMPORT_FS
|
199
176
|
s(:send, s(:attr, nil, :fs), :linkSync, *process_all(args))
|
200
177
|
|
201
178
|
elsif method == :ln_s and args.length == 2
|
202
|
-
|
179
|
+
prepend_list << IMPORT_FS
|
203
180
|
s(:send, s(:attr, nil, :fs), :symlinkSync, *process_all(args))
|
204
181
|
|
205
182
|
elsif method == :rm and args.length == 1
|
206
|
-
|
183
|
+
prepend_list << IMPORT_FS
|
207
184
|
S(:begin, *list[args.last].map {|file|
|
208
185
|
s(:send, s(:attr, nil, :fs), :unlinkSync, process(file))
|
209
186
|
})
|
@@ -211,7 +188,7 @@ module Ruby2JS
|
|
211
188
|
elsif \
|
212
189
|
method == :chmod and args.length == 2 and args.first.type == :int
|
213
190
|
then
|
214
|
-
|
191
|
+
prepend_list << IMPORT_FS
|
215
192
|
|
216
193
|
S(:begin, *list[args.last].map {|file|
|
217
194
|
S(:send, s(:attr, nil, :fs), method.to_s + 'Sync', process(file),
|
@@ -222,14 +199,14 @@ module Ruby2JS
|
|
222
199
|
method == :chown and args.length == 3 and
|
223
200
|
args[0].type == :int and args[1].type == :int
|
224
201
|
then
|
225
|
-
|
202
|
+
prepend_list << IMPORT_FS
|
226
203
|
|
227
204
|
S(:begin, *list[args.last].map {|file|
|
228
205
|
s(:send, s(:attr, nil, :fs), method.to_s + 'Sync', process(file),
|
229
206
|
*process_all(args[0..1]))})
|
230
207
|
|
231
208
|
elsif method == :touch
|
232
|
-
|
209
|
+
prepend_list << IMPORT_FS
|
233
210
|
|
234
211
|
S(:begin, *list[args.first].map {|file|
|
235
212
|
S(:send, s(:attr, nil, :fs), :closeSync,
|
@@ -249,16 +226,16 @@ module Ruby2JS
|
|
249
226
|
elsif method == :pwd and args.length == 0
|
250
227
|
s(:send, s(:attr, nil, :process), :cwd)
|
251
228
|
elsif method == :entries
|
252
|
-
|
229
|
+
prepend_list << IMPORT_FS
|
253
230
|
s(:send, s(:attr, nil, :fs), :readdirSync, *process_all(args))
|
254
231
|
elsif method == :mkdir and args.length == 1
|
255
|
-
|
232
|
+
prepend_list << IMPORT_FS
|
256
233
|
s(:send, s(:attr, nil, :fs), :mkdirSync, process(args.first))
|
257
234
|
elsif method == :rmdir and args.length == 1
|
258
|
-
|
235
|
+
prepend_list << IMPORT_FS
|
259
236
|
s(:send, s(:attr, nil, :fs), :rmdirSync, process(args.first))
|
260
237
|
elsif method == :mktmpdir and args.length <=1
|
261
|
-
|
238
|
+
prepend_list << IMPORT_FS
|
262
239
|
if args.length == 0
|
263
240
|
prefix = s(:str, 'd')
|
264
241
|
elsif args.first.type == :array
|
@@ -298,7 +275,7 @@ module Ruby2JS
|
|
298
275
|
|
299
276
|
def on_const(node)
|
300
277
|
if node.children == [nil, :ARGV]
|
301
|
-
|
278
|
+
prepend_list << SETUP_ARGV
|
302
279
|
super
|
303
280
|
elsif node.children == [nil, :ENV]
|
304
281
|
S(:attr, s(:attr, nil, :process), :env)
|
@@ -326,7 +303,7 @@ module Ruby2JS
|
|
326
303
|
end
|
327
304
|
|
328
305
|
def on_xstr(node)
|
329
|
-
|
306
|
+
prepend_list << IMPORT_CHILD_PROCESS
|
330
307
|
|
331
308
|
children = node.children.dup
|
332
309
|
command = children.shift
|
@@ -7,33 +7,7 @@ module Ruby2JS
|
|
7
7
|
include SEXP
|
8
8
|
extend SEXP
|
9
9
|
|
10
|
-
|
11
|
-
jsdom: s(:casgn, nil, :JSDOM,
|
12
|
-
s(:attr, s(:send, nil, :require, s(:str, "jsdom")), :JSDOM))
|
13
|
-
}
|
14
|
-
|
15
|
-
ESM_SETUP = {
|
16
|
-
jsdom: s(:import, ["jsdom"], [s(:attr, nil, :JSDOM)])
|
17
|
-
}
|
18
|
-
|
19
|
-
def initialize(*args)
|
20
|
-
@nokogiri_setup = nil
|
21
|
-
super
|
22
|
-
end
|
23
|
-
|
24
|
-
def process(node)
|
25
|
-
return super if @nokogiri_setup
|
26
|
-
@nokogiri_setup = Set.new
|
27
|
-
result = super
|
28
|
-
|
29
|
-
if @nokogiri_setup.empty?
|
30
|
-
result
|
31
|
-
else
|
32
|
-
setup = @esm ? ESM_SETUP : CJS_SETUP;
|
33
|
-
s(:begin,
|
34
|
-
*@nokogiri_setup.to_a.map {|token| setup[token]}, result)
|
35
|
-
end
|
36
|
-
end
|
10
|
+
IMPORT_JSDOM = s(:import, ["jsdom"], [s(:attr, nil, :JSDOM)])
|
37
11
|
|
38
12
|
def on_send(node)
|
39
13
|
target, method, *args = node.children
|
@@ -55,7 +29,7 @@ module Ruby2JS
|
|
55
29
|
[:HTML, :HTML5].include? method and
|
56
30
|
target == s(:const, nil, :Nokogiri)
|
57
31
|
then
|
58
|
-
|
32
|
+
prepend_list << IMPORT_JSDOM
|
59
33
|
S(:attr, s(:attr, s(:send, s(:const, nil, :JSDOM), :new,
|
60
34
|
*process_all(args)), :window), :document)
|
61
35
|
|
@@ -65,7 +39,7 @@ module Ruby2JS
|
|
65
39
|
target.children.first == s(:const, nil, :Nokogiri) and
|
66
40
|
[:HTML, :HTML5].include? target.children.last
|
67
41
|
then
|
68
|
-
|
42
|
+
prepend_list << IMPORT_JSDOM
|
69
43
|
S(:attr, s(:attr, s(:send, s(:const, nil, :JSDOM), :new,
|
70
44
|
*process_all(args)), :window), :document)
|
71
45
|
|
@@ -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
|
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/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.5.
|
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-
|
11
|
+
date: 2020-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -135,6 +135,7 @@ files:
|
|
135
135
|
- lib/ruby2js/filter/react.rb
|
136
136
|
- lib/ruby2js/filter/require.rb
|
137
137
|
- lib/ruby2js/filter/return.rb
|
138
|
+
- lib/ruby2js/filter/securerandom.rb
|
138
139
|
- lib/ruby2js/filter/tagged_templates.rb
|
139
140
|
- lib/ruby2js/filter/underscore.rb
|
140
141
|
- lib/ruby2js/filter/vue.rb
|