ruby2js 4.1.2 → 4.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 696f01a3f2781f8821257f1d2d0ed832e45a9fbde25c2f6f9f200ced90b24dab
4
- data.tar.gz: d4bc6d38fb7146b3615e621e7c86fc8e864895d377d10ecf69599fa60b7808d3
3
+ metadata.gz: 8f29494a95eb89f049d35d1a431e50e1ac4fb526fbe7544dff5b7c699b2aae9c
4
+ data.tar.gz: cd87036fc9542ce81e7dedb379ee5eb874f7ea9144096ff7f1b496b2c3bad5a3
5
5
  SHA512:
6
- metadata.gz: f82772a1dc3aefde7a5acb6b7ca3b05a083dbb3e4c9bbdcf585387ae950c6d410280dfe069d0be3d5fd5e28a5eb0524f2c35ccac83c3b9789109a45e2ceb29a9
7
- data.tar.gz: dffb0cd058bc9cdf28b76e99d73cb4916792bd9160ff9516994b3de2bc1b46e22c5d5be9bb772ec0f62c5947f5d73218e9d5fbd69e5e8a28b450875b92940ed7
6
+ metadata.gz: 574b8d730585898be4ce8506b256f90a9ed092e88edcbe5af82cf5d0f70aa7177b31486deee3b615269fe8011f0b9ac0efb38381bf6df924d04cfddcd5dda799
7
+ data.tar.gz: 68d618097efa0fc47509129242d84e72349dd3619b9238df83820ade29fca243d7cb19c6627d9fe5b14c64fb3fb6a5fa1d9f1cfa93bd2a5753acb84645a56fc4
@@ -17,8 +17,8 @@ module Ruby2JS
17
17
 
18
18
  LOGICAL = :and, :not, :or
19
19
  OPERATORS = [:[], :[]=], [:not, :!], [:**], [:*, :/, :%], [:+, :-],
20
- [:>>, :<<], [:&], [:^, :|], [:<=, :<, :>, :>=], [:==, :!=, :===, :"!=="],
21
- [:and, :or]
20
+ [:>>, :<<], [:&], [:^, :|], [:<=, :<, :>, :>=],
21
+ [:==, :!=, :===, :"!==", :=~, :!~], [:and, :or]
22
22
 
23
23
  INVERT_OP = {
24
24
  :< => :>=,
@@ -169,7 +169,9 @@ module Ruby2JS
169
169
  put 'function'
170
170
  end
171
171
 
172
- put '('; parse args; put ") {#{nl}"
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,16 +69,16 @@ 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
76
- right.updated(:csend, [left, right.children.last])
76
+ right.updated(:csend, [left, *right.children[1..-1]])
77
77
  elsif conditionally_equals(left.children.last, right.children.first)
78
78
  # a && b && b.c => a && b&.c
79
79
  left.updated(:and, [left.children.first,
80
80
  left.children.last.updated(:csend,
81
- [left.children.last, right.children.last])])
81
+ [left.children.last, *right.children[1..-1]])])
82
82
  else
83
83
  s(:and, left, right)
84
84
  end
@@ -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] =~ /_.*\w$/ and !ALLOWLIST.include?(node.children[0].to_s)
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] =~ /_.*\w$/
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
- process on_send S(:send, target, :[], s(:int, -1))
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
- process S(:send, S(:attr, target, :length), :-,
362
- s(:int, -index.children.first))
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
@@ -36,7 +36,7 @@ module Ruby2JS
36
36
  end
37
37
 
38
38
  def on_class(node)
39
- cname, inheritance, *body = node.children
39
+ _, inheritance, *body = node.children
40
40
  return super unless inheritance == s(:const, nil, :LitElement)
41
41
 
42
42
  @le_props = {}
@@ -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
- process ast
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
 
@@ -2,7 +2,7 @@ module Ruby2JS
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 4
4
4
  MINOR = 1
5
- TINY = 2
5
+ TINY = 6
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
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.2
4
+ version: 4.1.6
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-04-11 00:00:00.000000000 Z
12
+ date: 2021-08-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: parser