Code coverage report for 6to5/generation/node/index.js

Statements: 98.04% (50 / 51)      Branches: 95.45% (21 / 22)      Functions: 100% (12 / 12)      Lines: 100% (46 / 46)      Ignored: none     

All files » 6to5/generation/node/ » index.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 801   1 1 1 1   1 30225   30225 232918 5974 5974       30225     1 72146 72146     1 47558     1 6760 6760 6760   6695 2170     6695 6695   5703 462 462   5703     1 3149     1 3149     1 17828 17828   17828   17828 1 4       17827     1 5 72146   72146 72146      
module.exports = Node;
 
var whitespace = require("./whitespace");
var parens     = require("./parentheses");
var t          = require("../../types");
var _          = require("lodash");
 
var find = function (obj, node, parent) {
  var result;
 
  _.each(obj, function (fn, type) {
    if (t["is" + type](node)) {
      result = fn(node, parent);
      if (result != null) return false;
    }
  });
 
  return result;
};
 
function Node(node, parent) {
  this.parent = parent;
  this.node   = node;
}
 
Node.prototype.isUserWhitespacable = function () {
  return t.isUserWhitespacable(this.node);
};
 
Node.prototype.needsWhitespace = function (type) {
  var parent = this.parent;
  var node   = this.node;
  if (!node) return 0;
 
  if (t.isExpressionStatement(node)) {
    node = node.expression;
  }
 
  var lines = find(whitespace[type].nodes, node, parent);
  if (lines) return lines;
 
  _.each(find(whitespace[type].list, node, parent), function (expr) {
    lines = Node.needsWhitespace(expr, node, type);
    if (lines) return false;
  });
  return lines || 0;
};
 
Node.prototype.needsWhitespaceBefore = function () {
  return this.needsWhitespace("before");
};
 
Node.prototype.needsWhitespaceAfter = function () {
  return this.needsWhitespace("after");
};
 
Node.prototype.needsParens = function () {
  var parent = this.parent;
  var node   = this.node;
 
  Iif (!parent) return false;
 
  if (t.isNewExpression(parent) && parent.callee === node) {
    return t.isCallExpression(node) || _.some(node, function (val) {
      return t.isCallExpression(val);
    });
  }
 
  return find(parens, node, parent);
};
 
_.each(Node.prototype, function (fn, key) {
  Node[key] = function (node, parent) {
    var n = new Node(node, parent);
 
    var args = _.toArray(arguments).slice(2);
    return n[key].apply(n, args);
  };
});