Sha256: c2067f18be9d54e69907f070180ff4c1322ae7b0cd5d9c21748a4d5ecd0a3ef1
Contents?: true
Size: 1.44 KB
Versions: 19
Compression:
Stored size: 1.44 KB
Contents
module Ruby2JS class Converter # (args # (arg :a) # (restarg :b) # (blockarg :c)) handle :args do |*args| kwargs = [] while args.last and [:kwarg, :kwoptarg, :kwrestarg].include? args.last.type kwargs.unshift args.pop end if kwargs.length == 1 and kwargs.last.type == :kwrestarg args.push s(:arg, *kwargs.last.children) end unless kwargs.empty? or es2015 raise NotImplementedError.new('Keyword args require ES2015') end parse_all(*args, join: ', ') if not kwargs.empty? put ', ' unless args.empty? put '{ ' kwargs.each_with_index do |kw, index| put ', ' unless index == 0 if kw.type == :kwarg put kw.children.first elsif kw.type == :kwoptarg put kw.children.first unless kw.children.last == s(:send, nil, :undefined) put '='; parse kw.children.last end elsif kw.type == :kwrestarg raise 'Rest arg requires ES2018' unless es2018 put '...'; put kw.children.first end end put ' }' put ' = {}' unless kwargs.any? {|kw| kw.type == :kwarg} end end handle :mlhs do |*args| if es2015 or @jsx put '[' parse_all(*args, join: ', ') put ']' else raise Error.new("destructuring requires ES2015", @ast) end end end end
Version data entries
19 entries across 19 versions & 1 rubygems