Code coverage report for 6to5/transformation/transformers/es6-template-literals.js

Statements: 100% (33 / 33)      Branches: 100% (6 / 6)      Functions: 100% (3 / 3)      Lines: 100% (31 / 31)      Ignored: none     

All files » 6to5/transformation/transformers/ » es6-template-literals.js
1 2 3 4 5 6 7 8 9 10 11 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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 591   1 13     1 1 1   1 1   1 3 3 3     1         1   1     1 8 8   8 17   17   17 17     8   6 6   6   6 7     6   2      
var t = require("../../types");
 
var buildBinaryExpression = function (left, right) {
  return t.binaryExpression("+", left, right);
};
 
exports.TaggedTemplateExpression = function (node, parent, file) {
  var args = [];
  var quasi = node.quasi;
 
  var strings = [];
  var raw = [];
 
  for (var i in quasi.quasis) {
    var elem = quasi.quasis[i];
    strings.push(t.literal(elem.value.cooked));
    raw.push(t.literal(elem.value.raw));
  }
 
  args.push(t.callExpression(file.addDeclaration("tagged-template-literal"), [
    t.arrayExpression(strings),
    t.arrayExpression(raw)
  ]));
 
  args = args.concat(quasi.expressions);
 
  return t.callExpression(node.tag, args);
};
 
exports.TemplateLiteral = function (node) {
  var nodes = [];
  var i;
 
  for (i in node.quasis) {
    var elem = node.quasis[i];
 
    nodes.push(t.literal(elem.value.cooked));
 
    var expr = node.expressions.shift();
    if (expr) nodes.push(expr);
  }
 
  if (nodes.length > 1) {
    // remove redundant '' at the end of the expression
    var last = nodes[nodes.length - 1];
    if (t.isLiteral(last, { value: "" })) nodes.pop();
 
    var root = buildBinaryExpression(nodes.shift(), nodes.shift());
 
    for (i in nodes) {
      root = buildBinaryExpression(root, nodes[i]);
    }
 
    return root;
  } else {
    return nodes[0];
  }
};