ruby2js 4.1.4 → 4.1.5

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: 7ff40ad496d47d0ec4fa430f6d04b47b1c0d7ae6f152c479da8de49a9f506a00
4
- data.tar.gz: 84de6a0f644de7716d9e094f2944d896c49cafaca082523d4947a5d8f567eddc
3
+ metadata.gz: 412d541e9884847f722555edd11a71ead4c2358632976bf32f530ca270eb539b
4
+ data.tar.gz: f32b8d14177ee0f08466abfbb4a96017e6dc8a4e5a2226476c77f26affa7f81d
5
5
  SHA512:
6
- metadata.gz: 7f34521a4ef3677997f541721dfc5a0eb8e870a567ec2198b9b98e1f0d15270160bc076a070e0e5728b77a6622ba4ed0c133f20c9086dbec1cbb1d736bbe28a2
7
- data.tar.gz: 9196de55781c332df1183361bcf1428f51ccebb1e38eab2b2ab9f7e3b30b6502b4176eefac0539eb3079906b955e138ee95971822ea59a775a36af5ca27a8aa5
6
+ metadata.gz: c4be8efc1eb9ec2f1de81f5c0236b6ea3c868522043e305cb0dfcac80e61b1e57e5639f77ad2a0a6aa44b7b5eb87842db5a7072f42ab25ad625474904d88e4b8
7
+ data.tar.gz: 6f8c9c91f1ca05f4363023ee588e356226dbafcf09235d5ab25c5ffaef564109a4c653673bbf8a6da1c0b3a231f84231f25089fdd0c0207e7ddd6c8d25dfd7d7
@@ -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,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
@@ -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
@@ -69,7 +69,7 @@ module Ruby2JS
69
69
  def handle_generic_node(node, node_type)
70
70
  return node if node.type != node_type
71
71
 
72
- 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)
73
73
  S(node_type , camelCase(node.children[0]), *node.children[1..-1])
74
74
  else
75
75
  node
@@ -136,7 +136,7 @@ module Ruby2JS
136
136
  node = super
137
137
  return node if node.type != :defs
138
138
 
139
- if node.children[1] =~ /_.*\w$/
139
+ if node.children[1] =~ /_.*[?!\w]$/
140
140
  S(:defs , node.children[0],
141
141
  camelCase(node.children[1]), *node.children[2..-1])
142
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 = 4
5
+ TINY = 5
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.4
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-05-08 00:00:00.000000000 Z
12
+ date: 2021-08-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: parser
@@ -189,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
189
  - !ruby/object:Gem::Version
190
190
  version: '0'
191
191
  requirements: []
192
- rubygems_version: 3.1.4
192
+ rubygems_version: 3.1.2
193
193
  signing_key:
194
194
  specification_version: 4
195
195
  summary: Minimal yet extensible Ruby to JavaScript conversion.