ruby2js 3.0.1 → 3.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e26859d5b9002827f57c600965dd6b55df2b25c3
4
- data.tar.gz: 04ca04d344d2d48c70d135d9aecbe9078ff943ec
2
+ SHA256:
3
+ metadata.gz: '009edffb834a3c8c298d4ad601160d30c4781891a4fe7b229e6dbc6f4284569e'
4
+ data.tar.gz: 186d6e6ec33a0fee107623c3ed7994e9dea0741cf454bb79005acbb6be7f6429
5
5
  SHA512:
6
- metadata.gz: 5bf863d48a676e4d5980086604c446d9b9dff262b6c4fecd4511b2b3e79a3505883a9d5806f9815fa7b8c82d55a2ce989262ae019c41e2cd666501fce5b8cf51
7
- data.tar.gz: c8b93f23990824470b7e3ceaf527e95968644ea3422c4074b8f6d946406fbd62efd19256bdc6c6873063788d820f4a53d88ca127fdeaff8faae2bc1d51d1147b
6
+ metadata.gz: de2efb3d8d13a282af0401ce3a6216423564933483d3be4ed160eb1ef2bbf3092fdae6c9325d09298d6c86012de936c764178a0767a08b66b49b6d6d53bd9daa
7
+ data.tar.gz: 3558c528e771c98fd50ece66410dd12d3a33c57af85e89e47a1c04f743f4a531cb971dbdf197291f8e6b1530d1895ea9c40aaf8814d64d094eb2f397092504a2
@@ -21,6 +21,8 @@ module Ruby2JS
21
21
 
22
22
  GROUP_OPERATORS = [:begin, :dstr, :dsym, :and, :or]
23
23
 
24
+ VASGN = [:cvasgn, :ivasgn, :gvasgn, :lvasgn]
25
+
24
26
  attr_accessor :binding, :ivars
25
27
 
26
28
  def initialize( ast, comments, vars = {} )
@@ -5,6 +5,8 @@ module Ruby2JS
5
5
  # (int 1))
6
6
 
7
7
  handle :casgn do |cbase, var, value|
8
+ multi_assign_declarations if @state == :statement
9
+
8
10
  begin
9
11
  if es2015
10
12
  put "const "
@@ -5,6 +5,8 @@ module Ruby2JS
5
5
  # (int 1))
6
6
 
7
7
  handle :cvasgn do |var, expression=nil|
8
+ multi_assign_declarations if @state == :statement
9
+
8
10
  if @class_name
9
11
  parse @class_name
10
12
  put var.to_s.sub('@@', "._")
@@ -5,6 +5,8 @@ module Ruby2JS
5
5
  # (int 1))
6
6
 
7
7
  handle :ivasgn do |var, expression=nil|
8
+ multi_assign_declarations if @state == :statement
9
+
8
10
  put "#{ var.to_s.sub('@', 'this._') }"
9
11
  if expression
10
12
  put " = "; parse expression
@@ -151,6 +151,8 @@ module Ruby2JS
151
151
  (group_target ? group(target) : parse(target))
152
152
 
153
153
  elsif method =~ /=$/
154
+ multi_assign_declarations if @state == :statement
155
+
154
156
  parse receiver
155
157
  put "#{ '.' if receiver }#{ method.to_s.sub(/=$/, ' =') } "
156
158
  parse args.first, (@state == :method ? :method : :expression)
@@ -21,8 +21,13 @@ module Ruby2JS
21
21
  end
22
22
 
23
23
  unless undecls.empty?
24
- return parse s(:begin,
25
- *undecls.map {|uname| s(:lvasgn, uname)}, @ast), @state
24
+ if es2015
25
+ put 'let '
26
+ else
27
+ put 'var '
28
+ end
29
+ put undecls.map(&:to_s).join(', ') + @sep
30
+ undecls.each {|var| @vars[var] = true}
26
31
  end
27
32
  end
28
33
 
@@ -49,5 +54,39 @@ module Ruby2JS
49
54
  end
50
55
  end
51
56
  end
57
+
58
+ def multi_assign_declarations
59
+ undecls = []
60
+ child = @ast
61
+ loop do
62
+ if [:send, :casgn].include? child.type
63
+ subchild = child.children[2]
64
+ else
65
+ subchild = child.children[1]
66
+ end
67
+
68
+ if subchild.type == :send
69
+ break unless subchild.children[1] =~ /=$/
70
+ else
71
+ break unless [:send, :cvasgn, :ivasgn, :gvasgn, :lvasgn].
72
+ include? subchild.type
73
+ end
74
+
75
+ child = subchild
76
+
77
+ if child.type == :lvasgn and not @vars.include?(child.children[0])
78
+ undecls << child.children[0]
79
+ end
80
+ end
81
+
82
+ unless undecls.empty?
83
+ if es2015
84
+ put "let "
85
+ else
86
+ put "var "
87
+ end
88
+ put "#{undecls.map(&:to_s).join(', ')}#@sep"
89
+ end
90
+ end
52
91
  end
53
92
  end
@@ -17,8 +17,8 @@ module Ruby2JS
17
17
 
18
18
  if [:max, :min].include? method and args.length == 0
19
19
  return super unless node.is_method?
20
- process S(:send, s(:attr, s(:const, nil, :Math), node.children[1]),
21
- :apply, s(:const, nil, :Math), target)
20
+ process S(:send, s(:const, nil, :Math), node.children[1],
21
+ s(:splat, target))
22
22
 
23
23
  elsif method == :call and target and target.type == :ivar
24
24
  process S(:send, s(:self), "_#{target.children.first.to_s[1..-1]}",
@@ -2,7 +2,7 @@ module Ruby2JS
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 3
4
4
  MINOR = 0
5
- TINY = 1
5
+ TINY = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
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.0.1
4
+ version: 3.0.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: 2018-01-21 00:00:00.000000000 Z
11
+ date: 2018-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -130,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
130
  version: '0'
131
131
  requirements: []
132
132
  rubyforge_project:
133
- rubygems_version: 2.6.14
133
+ rubygems_version: 2.7.4
134
134
  signing_key:
135
135
  specification_version: 4
136
136
  summary: Minimal yet extensible Ruby to JavaScript conversion.