Sha256: 3e42895889558cf040c46d76a4921cc92b494e1990d90afe92421d53772b33ff
Contents?: true
Size: 1.35 KB
Versions: 18
Compression:
Stored size: 1.35 KB
Contents
module Ruby2JS class Converter # (dstr # (str 'a') # (...)) # (dsym # (str 'a') # (...)) handle :dstr, :dsym do |*children| if es2015 # gather length of string parts; if long enough, newlines will # not be escaped (poor man's HEREDOC) strings = children.select {|child| child.type==:str}. map {|child| child.children.last}.join heredoc = (strings.length > 40 and strings.scan("\n").length > 3) put '`' children.each do |child| if child.type == :str str = child.children.first.inspect[1..-2].gsub('${', '$\{') if heredoc put! str.gsub("\\n", "\n") else put str end else put '${' parse child put '}' end end put '`' return end children.each_with_index do |child, index| put ' + ' unless index == 0 if child.type == :begin and child.children.length == 1 child = child.children.first end if child.type == :send op_index = operator_index child.children[1] if op_index >= operator_index(:+) group child else parse child end else parse child end end end end end
Version data entries
18 entries across 18 versions & 1 rubygems