ruby2js 4.0.5 → 4.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ruby2js/converter.rb +1 -0
- data/lib/ruby2js/converter/class.rb +7 -5
- data/lib/ruby2js/converter/class2.rb +1 -1
- data/lib/ruby2js/converter/match.rb +7 -0
- data/lib/ruby2js/converter/send.rb +3 -3
- data/lib/ruby2js/converter/taglit.rb +6 -2
- data/lib/ruby2js/filter/camelCase.rb +17 -0
- data/lib/ruby2js/filter/cjs.rb +100 -2
- data/lib/ruby2js/filter/functions.rb +11 -6
- data/lib/ruby2js/filter/lit-element.rb +29 -13
- data/lib/ruby2js/filter/react.rb +275 -87
- data/lib/ruby2js/serializer.rb +41 -10
- data/lib/ruby2js/version.rb +2 -2
- data/lib/tasks/install/config/webpack/loaders/ruby2js.js +20 -0
- data/lib/tasks/install/preact.rb +3 -0
- data/lib/tasks/install/webpacker.rb +14 -31
- data/lib/tasks/ruby2js_tasks.rake +5 -0
- metadata +6 -3
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
@@ -0,0 +1,20 @@
|
|
1
|
+
const { environment } = require('@rails/webpacker')
|
2
|
+
|
3
|
+
module.exports = {
|
4
|
+
test: /\.js\.rb$/,
|
5
|
+
use: [
|
6
|
+
{
|
7
|
+
loader: "babel-loader",
|
8
|
+
options: environment.loaders.get('babel').use[0].options
|
9
|
+
},
|
10
|
+
|
11
|
+
{
|
12
|
+
loader: "@ruby2js/webpack-loader",
|
13
|
+
options: {
|
14
|
+
autoexports: "default",
|
15
|
+
eslevel: 2021,
|
16
|
+
filters: ["esm", "functions"]
|
17
|
+
}
|
18
|
+
}
|
19
|
+
]
|
20
|
+
}
|
@@ -27,40 +27,25 @@ insert_into_file Rails.root.join("config/webpacker.yml").to_s,
|
|
27
27
|
# install webpack loader
|
28
28
|
run "yarn add @ruby2js/webpack-loader #{@yarn_add}"
|
29
29
|
|
30
|
+
target = Rails.root.join("config/webpack/loaders/ruby2js.js").to_s
|
31
|
+
|
30
32
|
# default config
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
loader: "babel-loader",
|
38
|
-
options: environment.loaders.get('babel').use[0].options
|
39
|
-
},
|
33
|
+
if not File.exist? target
|
34
|
+
# may be called via eval, or directly. Resolve source either way.
|
35
|
+
source_paths.unshift __dir__
|
36
|
+
source_paths.unshift File.dirname(caller.first)
|
37
|
+
directory "config/webpack/loaders", File.dirname(target)
|
38
|
+
end
|
40
39
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
autoexports: "default",
|
45
|
-
eslevel: 2021,
|
46
|
-
filters: ["esm", "functions"]
|
47
|
-
}
|
48
|
-
},
|
49
|
-
]
|
50
|
-
})
|
51
|
-
CONFIG
|
40
|
+
# load config
|
41
|
+
insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
|
42
|
+
"environment.loaders.prepend('ruby2js', require('./loaders/ruby2js'))\n"
|
52
43
|
|
53
44
|
# read current configuration
|
54
|
-
target = Rails.root.join("config/webpack/environment.js").to_s
|
55
45
|
before = IO.read(target)
|
56
46
|
|
57
|
-
# extract indentation and options
|
58
|
-
|
59
|
-
if before.include? '@ruby2js/webpack-loader'
|
60
|
-
match = /^(\s*)options: (\{.*?\n\1\})/m.match(before)
|
61
|
-
else
|
62
|
-
match = /^(\s*)options: (\{.*?\n\1\})/m.match(config)
|
63
|
-
end
|
47
|
+
# extract indentation and options
|
48
|
+
match = /^(\s*)options: (\{.*?\n\1\})/m.match(before)
|
64
49
|
|
65
50
|
# evaluate base options. Here it is handy that Ruby's syntax for hashes is
|
66
51
|
# fairly close to JavaScript's object literals. May run into problems in the
|
@@ -90,8 +75,6 @@ replacement = Ruby2JS.convert(merged.inspect + "\n").to_s.
|
|
90
75
|
gsub(/^/, match[1]).strip
|
91
76
|
|
92
77
|
# Update configuration
|
93
|
-
|
78
|
+
unless before.include? replacement
|
94
79
|
gsub_file target, match[2].to_s, replacement
|
95
|
-
else
|
96
|
-
append_to_file target, "\n" + config.sub(match[2], replacement)
|
97
80
|
end
|
@@ -12,6 +12,11 @@ namespace :ruby2js do
|
|
12
12
|
template 'install/litelement.rb'
|
13
13
|
end
|
14
14
|
|
15
|
+
desc "Install Ruby2JS with Preact support"
|
16
|
+
task :preact do
|
17
|
+
template 'install/preact.rb'
|
18
|
+
end
|
19
|
+
|
15
20
|
desc "Install Ruby2JS with React support"
|
16
21
|
task :react do
|
17
22
|
template 'install/react.rb'
|
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.
|
4
|
+
version: 4.1.4
|
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-05-08 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
|
@@ -159,7 +160,9 @@ files:
|
|
159
160
|
- lib/ruby2js/version.rb
|
160
161
|
- lib/tasks/README.md
|
161
162
|
- lib/tasks/install/app/javascript/elements/index.js
|
163
|
+
- lib/tasks/install/config/webpack/loaders/ruby2js.js
|
162
164
|
- lib/tasks/install/litelement.rb
|
165
|
+
- lib/tasks/install/preact.rb
|
163
166
|
- lib/tasks/install/react.rb
|
164
167
|
- lib/tasks/install/stimulus-sprockets.rb
|
165
168
|
- lib/tasks/install/stimulus-webpacker.rb
|
@@ -186,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
186
189
|
- !ruby/object:Gem::Version
|
187
190
|
version: '0'
|
188
191
|
requirements: []
|
189
|
-
rubygems_version: 3.1.
|
192
|
+
rubygems_version: 3.1.4
|
190
193
|
signing_key:
|
191
194
|
specification_version: 4
|
192
195
|
summary: Minimal yet extensible Ruby to JavaScript conversion.
|