Code coverage report for 6to5/lib/6to5/generation/generators/expressions.js

Statements: 98.85% (86 / 87)      Branches: 92.31% (36 / 39)      Functions: 100% (13 / 13)      Lines: 98.82% (84 / 85)      Ignored: none     

All files » 6to5/lib/6to5/generation/generators/ » expressions.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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 1461 1 1   1 17627 17627   17627 134     17627 16     17627 17627 17627     1 2316 169 169   2147 2147       1 344 344 344 344 344     1 6622 6622 6622 6622 6622 6622       1 92     1 2116     1 63857   63857   63857   63857 9 9 9   63848     63857       63857 9 9     63857     1 2 15 15 15 15 15         1 1   1 811     1 63302 63302     1       106052 106052 106052     1   1 60354 60354   60354       60354 60354 6628     60354 9736 9736 9736     50618 15     50618 50618      
var util = require("../../util");
var t    = require("../../types");
var _    = require("lodash");
 
exports.UnaryExpression = function (node, print) {
  var hasSpace = /[a-z]$/.test(node.operator);
  var arg = node.argument;
 
  if (t.isUpdateExpression(arg) || t.isUnaryExpression(arg)) {
    hasSpace = true;
  }
 
  if (t.isUnaryExpression(arg) && arg.operator === "!") {
    hasSpace = false;
  }
 
  this.push(node.operator);
  if (hasSpace) this.space();
  print(node.argument);
};
 
exports.UpdateExpression = function (node, print) {
  if (node.prefix) {
    this.push(node.operator);
    print(node.argument);
  } else {
    print(node.argument);
    this.push(node.operator);
  }
};
 
exports.ConditionalExpression = function (node, print) {
  print(node.test);
  this.push(" ? ");
  print(node.consequent);
  this.push(" : ");
  print(node.alternate);
};
 
exports.NewExpression = function (node, print) {
  this.push("new ");
  print(node.callee);
  Eif (node.arguments.length || this.format.parentheses) {
    this.push("(");
    print.join(node.arguments, { separator: ", " });
    this.push(")");
  }
};
 
exports.SequenceExpression = function (node, print) {
  print.join(node.expressions, { separator: ", " });
};
 
exports.ThisExpression = function () {
  this.push("this");
};
 
exports.CallExpression = function (node, print) {
  print(node.callee);
 
  this.push("(");
 
  var separator = ",";
 
  if (node._prettyCall) {
    separator += "\n";
    this.newline();
    this.indent();
  } else {
    separator += " ";
  }
 
  print.join(node.arguments, {
    separator: separator
  });
 
  if (node._prettyCall) {
    this.newline();
    this.dedent();
  }
 
  this.push(")");
};
 
var buildYieldAwait = function (keyword) {
  return function (node, print) {
    this.push(keyword);
    if (node.delegate) this.push("*");
    Eif (node.argument) {
      this.space();
      print(node.argument);
    }
  };
};
 
exports.YieldExpression = buildYieldAwait("yield");
exports.AwaitExpression = buildYieldAwait("await");
 
exports.EmptyStatement = function () {
  this.semicolon();
};
 
exports.ExpressionStatement = function (node, print) {
  print(node.expression);
  this.semicolon();
};
 
exports.BinaryExpression =
exports.LogicalExpression =
exports.AssignmentPattern =
exports.AssignmentExpression = function (node, print) {
  print(node.left);
  this.push(" " + node.operator + " ");
  print(node.right);
};
 
var SCIENTIFIC_NOTATION = /e/i;
 
exports.MemberExpression = function (node, print) {
  var obj = node.object;
  print(obj);
 
  Iif (!node.computed && t.isMemberExpression(node.property)) {
    throw new TypeError("Got a MemberExpression for MemberExpression property");
  }
 
  var computed = node.computed;
  if (t.isLiteral(node.property) && _.isNumber(node.property.value)) {
    computed = true;
  }
 
  if (computed) {
    this.push("[");
    print(node.property);
    this.push("]");
  } else {
    // 5..toFixed(2);
    if (t.isLiteral(obj) && util.isInteger(obj.value) && !SCIENTIFIC_NOTATION.test(obj.value.toString())) {
      this.push(".");
    }
 
    this.push(".");
    print(node.property);
  }
};