lib/ruby2js/converter/class2.rb in ruby2js-3.0.9 vs lib/ruby2js/converter/class2.rb in ruby2js-3.0.10
- old
+ new
@@ -122,11 +122,19 @@
m.children[2..-1].each_with_index do |child_sym, index2|
put @sep unless index2 == 0
var = child_sym.children.first
put "set #{var}(#{var}) {#{@nl}this._#{var} = #{var}#@nl}"
end
+ elsif [:private, :protected, :public].include? m.children[1]
+ raise Error.new("class #{m.children[1]} is not supported", @ast)
else
+ if m.children[1] == :include
+ m = m.updated(:begin, m.children[2..-1].map {|mname|
+ s(:send, s(:const, nil, :Object), :assign,
+ s(:attr, name, :prototype), mname)})
+ end
+
skipped = true
end
else
skipped = true
@@ -137,28 +145,40 @@
@rbstack.last[m.children[0]] = name
end
end
if skipped
- post << m if skipped
+ post << [m, comments] if skipped
else
comments.reverse.each {|comment| insert location, comment}
end
end
put @nl unless skipped
put '}'
- post.each do |m|
+ post.each do |m, comments|
put @sep
+ comments.each {|comment| put comment}
if m.type == :alias
parse name
put '.prototype.'
put m.children[0].children[0]
put ' = '
parse name
put '.prototype.'
put m.children[1].children[0]
+ elsif m.type == :class
+ innerclass_name = m.children.first
+ if innerclass_name.children.first
+ innerclass_name = innerclass_name.updated(nil,
+ [s(:attr, innerclass_name.children[0], name),
+ innerclass_name.children[1]])
+ else
+ innerclass_name = innerclass_name.updated(nil,
+ [name, innerclass_name.children[1]])
+ end
+ parse m.updated(nil, [innerclass_name, *m.children[1..-1]])
else
parse m, :statement
end
end