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

Statements: 100% (53 / 53)      Branches: 100% (32 / 32)      Functions: 100% (5 / 5)      Lines: 100% (48 / 48)      Ignored: none     

All files » 6to5/lib/6to5/generation/generators/ » methods.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 831   1 15898   15898   15898     7468 7468 7 7         15898 4 3     4 4     15898     1 54 54 54   54 29 11     25     54   54 23 23 23   31     54 54 54     1   15837 15837 15837 15837 15837 15837 15837 15837     1 14   14 7   7     14 14    
var t = require("../../types");
 
exports._params = function (node, print) {
  var self = this;
 
  this.push("(");
 
  print.join(node.params, {
    separator: ", ",
    iterator: function (param, i) {
      var def = node.defaults && node.defaults[i];
      if (def) {
        self.push(" = ");
        print(def);
      }
    }
  });
 
  if (node.rest) {
    if (node.params.length) {
      this.push(", ");
    }
 
    this.push("...");
    print(node.rest);
  }
 
  this.push(")");
};
 
exports._method = function (node, print) {
  var value = node.value;
  var kind  = node.kind;
  var key   = node.key;
 
  if (!kind || kind === "init") {
    if (value.generator) {
      this.push("*");
    }
  } else {
    this.push(kind + " ");
  }
 
  if (value.async) this.push("async ");
 
  if (node.computed) {
    this.push("[");
    print(key);
    this.push("]");
  } else {
    print(key);
  }
 
  this._params(value, print);
  this.space();
  print(value.body);
};
 
exports.FunctionDeclaration =
exports.FunctionExpression = function (node, print) {
  if (node.async) this.push("async ");
  this.push("function");
  if (node.generator) this.push("*");
  this.space();
  if (node.id) print(node.id);
  this._params(node, print);
  this.space();
  print(node.body);
};
 
exports.ArrowFunctionExpression = function (node, print) {
  if (node.async) this.push("async ");
 
  if (node.params.length === 1 && !node.defaults.length && !node.rest && t.isIdentifier(node.params[0])) {
    print(node.params[0]);
  } else {
    this._params(node, print);
  }
 
  this.push(" => ");
  print(node.body);
};