lib/ruby2js/converter/begin.rb in ruby2js-1.15.1 vs lib/ruby2js/converter/begin.rb in ruby2js-2.0.0
- old
+ new
@@ -26,18 +26,32 @@
if props
combine_properties(statements) if props
statements.compact!
end
- statements.map{ |statement| parse statement, state }.join(@sep)
+ parse_all *statements, state: state, join: @sep
end
def combine_properties(body)
for i in 0...body.length-1
next unless body[i] and body[i].type == :prop
for j in i+1...body.length
break unless body[j] and body[j].type == :prop
+
if body[i].children[0] == body[j].children[0]
+ # relocate property comment to first method
+ [body[i], body[j]].each do |node|
+ unless @comments[node].empty?
+ node.children[1].values.first.each do |key, value|
+ if [:get, :set].include? key and Parser::AST::Node === value
+ @comments[value] = @comments[node]
+ break
+ end
+ end
+ end
+ end
+
+ # merge properties
merge = Hash[(body[i].children[1].to_a+body[j].children[1].to_a).
group_by {|name, value| name.to_s}.map {|name, values|
[name, values.map(&:last).reduce(:merge)]}]
body[j] = s(:prop, body[j].children[0], merge)
body[i] = nil