Code coverage report for 6to5/generation/generators/types.js

Statements: 94.23% (49 / 52)      Branches: 85.71% (24 / 28)      Functions: 100% (7 / 7)      Lines: 93.88% (46 / 49)      Ignored: none     

All files » 6to5/generation/generators/ » types.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 871   1 3080     1 4 4     1   106   106 92 92   92   92 92   14       1 160 5   155 10 10 10   145 145     140 140       1   122 122 122   122   122 219               219 219 219       122     1 893 893   893 856 37 2 35 35          
var _ = require("lodash");
 
exports.Identifier = function (node) {
  this.push(node.name);
};
 
exports.SpreadElement = function (node, print) {
  this.push("...");
  print(node.argument);
};
 
exports.ObjectExpression =
exports.ObjectPattern = function (node, print) {
  var props = node.properties;
 
  if (props.length) {
    this.push("{");
    this.space();
 
    print.join(props, { separator: ", ", indent: true });
 
    this.space();
    this.push("}");
  } else {
    this.push("{}");
  }
};
 
exports.Property = function (node, print) {
  if (node.method || node.kind === "get" || node.kind === "set") {
    this._method(node, print);
  } else {
    if (node.computed) {
      this.push("[");
      print(node.key);
      this.push("]");
    } else {
      print(node.key);
      if (node.shorthand) return;
    }
 
    this.push(": ");
    print(node.value);
  }
};
 
exports.ArrayExpression =
exports.ArrayPattern = function (node, print) {
  var elems = node.elements;
  var self  = this;
  var len   = elems.length;
 
  this.push("[");
 
  _.each(elems, function (elem, i) {
    Iif (!elem) {
      // If the array expression ends with a hole, that hole
      // will be ignored by the interpreter, but if it ends with
      // two (or more) holes, we need to write out two (or more)
      // commas so that the resulting code is interpreted with
      // both (all) of the holes.
      self.push(",");
    } else {
      if (i > 0) self.push(" ");
      print(elem);
      if (i < len - 1) self.push(",");
    }
  });
 
  this.push("]");
};
 
exports.Literal = function (node) {
  var val  = node.value;
  var type = typeof val;
 
  if (type === "boolean" || type === "number" || type === "string") {
    this.push(JSON.stringify(val));
  } else if (node.regex) {
    this.push("/" + node.regex.pattern + "/" + node.regex.flags);
  } else Eif (val === null) {
    this.push("null");
  } else if (node.raw) {
    this.push(node.raw);
  }
};