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

Statements: 100% (55 / 55)      Branches: 96.3% (26 / 27)      Functions: 100% (8 / 8)      Lines: 100% (52 / 52)      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 87 88 89 90 91 92 93 941   1 3718     1 7 7     1   121   121 101 101   101   101 101   20       1 186 11   175 11 11 11   164 164     161 161       1   137 137 137   137   137 250           5   245 245 245       137     1 1047 1047   1047 561     561 6     561 486 442 44 3 41 41      
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) {
    if (!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 === "string") {
    val = JSON.stringify(val);
 
    // escape unicode characters
    val = val.replace(/[\u007f-\uffff]/g, function(c) {
      return "\\u" + ("0000" + c.charCodeAt(0).toString(16)).slice(-4);
    });
 
    this.push(val);
  } else if (type === "boolean" || type === "number") {
    this.push(JSON.stringify(val));
  } else if (node.regex) {
    this.push("/" + node.regex.pattern + "/" + node.regex.flags);
  } else Eif (val === null) {
    this.push("null");
  }
};