Module: Ruby2JS::Filter::TaggedTemplates

Includes:
SEXP
Defined in:
lib/ruby2js/filter/tagged_templates.rb

Instance Method Summary collapse

Methods included from SEXP

#S, #s

Instance Method Details

#initialize(*args) ⇒ Object



8
9
10
# File 'lib/ruby2js/filter/tagged_templates.rb', line 8

def initialize(*args)
  super
end

#on_send(node) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ruby2js/filter/tagged_templates.rb', line 12

def on_send(node)
  target, method, *args = node.children
  return super unless target.nil? and es2015

  tagged_methods = @options[:template_literal_tags] || [:html, :css]

  if tagged_methods.include?(method) && args.length == 1
    strnode = process args.first
    if strnode.type == :str
      # convert regular strings to literal strings
      strnode = strnode.updated(:dstr, [s(:str, strnode.children.first.chomp("\n"))])
    elsif strnode.type == :dstr
      # for literal strings, chomp a newline off the end
      if strnode.children.last.type == :str && strnode.children.last.children[0].end_with?("\n")
       children = [*strnode.children.take(strnode.children.length - 1), s(:str, strnode.children.last.children[0].chomp)]
       strnode = s(:dstr, *children)
      end
    else
      return super
    end

    S(:taglit, s(:sym, method), strnode)
  else
    super
  end
end