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

Statements: 97.7% (85 / 87)      Branches: 89.74% (35 / 39)      Functions: 100% (13 / 13)      Lines: 97.65% (83 / 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 236 236   236 13     236 5     236 236 236     1 58 10 10   48 48       1 82 82 82 82 82     1 94 94 94 94 94 94       1 32     1 214     1 2019   2019   2019   2019 9 9 9   2010     2019       2019 9 9     2019     1 2 15 15 15 15 15         1 1   1 4     1 1846 1846     1       1474 1474 1474     1   1 2745 2745   2745       2745 2745 132     2745 422 422 422     2323       2323 2323      
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);
    Iif (t.isLiteral(obj) && util.isInteger(obj.value) && !SCIENTIFIC_NOTATION.test(obj.value.toString())) {
      this.push(".");
    }
 
    this.push(".");
    print(node.property);
  }
};