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

Statements: 100% (134 / 134)      Branches: 100% (24 / 24)      Functions: 100% (19 / 19)      Lines: 100% (133 / 133)      Ignored: none     

All files » 6to5/lib/6to5/generation/generators/ » statements.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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 2001 1   1 289 289 289 289 289     1 29967 29967 29967 29967   29967   29967 1346 1346 1346       1 1720 1720   1720 1720   1720 1694 1694   1720   1720 1607 1607     1720 1720     1 61 61 61 61 61     1 2 885 885 885 885 885 885 885       1 1   1 85 85 85 85 85 85 85     1 3 14146   14146 14146 13776 13776     14146       1 1 1   1 89 89 89     1 3339 3339 3339 3339 3339 668 668 668       1 2773 2773 2773 2773 2773     1 849 849 849     1 23 23 23 23 23 23     1 86 70 70 70   16     86 86     1 1     1 23712   23712 23712 23712 24435 22699   1736       23712 23712 22212   1500     23712   23712 21654       1 4 4 4     1 24435 22699 22699 22699   1736      
var util = require("../../util");
var t    = require("../../types");
 
exports.WithStatement = function (node, print) {
  this.keyword("with");
  this.push("(");
  print(node.object);
  this.push(")");
  print.block(node.body);
};
 
exports.IfStatement = function (node, print) {
  this.keyword("if");
  this.push("(");
  print(node.test);
  this.push(") ");
 
  print.indentOnComments(node.consequent);
 
  if (node.alternate) {
    if (this.isLast("}")) this.space();
    this.keyword("else");
    print.indentOnComments(node.alternate);
  }
};
 
exports.ForStatement = function (node, print) {
  this.keyword("for");
  this.push("(");
 
  print(node.init);
  this.push(";");
 
  if (node.test) {
    this.space();
    print(node.test);
  }
  this.push(";");
 
  if (node.update) {
    this.space();
    print(node.update);
  }
 
  this.push(")");
  print.block(node.body);
};
 
exports.WhileStatement = function (node, print) {
  this.keyword("while");
  this.push("(");
  print(node.test);
  this.push(")");
  print.block(node.body);
};
 
var buildForXStatement = function (op) {
  return function (node, print) {
    this.keyword("for");
    this.push("(");
    print(node.left);
    this.push(" " + op + " ");
    print(node.right);
    this.push(")");
    print.block(node.body);
  };
};
 
exports.ForInStatement = buildForXStatement("in");
exports.ForOfStatement = buildForXStatement("of");
 
exports.DoWhileStatement = function (node, print) {
  this.keyword("do");
  print(node.body);
  this.space();
  this.keyword("while");
  this.push("(");
  print(node.test);
  this.push(");");
};
 
var buildLabelStatement = function (prefix, key) {
  return function (node, print) {
    this.push(prefix);
 
    var label = node[key || "label"];
    if (label) {
      this.space();
      print(label);
    }
 
    this.semicolon();
  };
};
 
exports.ContinueStatement = buildLabelStatement("continue");
exports.ReturnStatement   = buildLabelStatement("return", "argument");
exports.BreakStatement    = buildLabelStatement("break");
 
exports.LabeledStatement = function (node, print) {
  print(node.label);
  this.push(": ");
  print(node.body);
};
 
exports.TryStatement = function (node, print) {
  this.keyword("try");
  print(node.block);
  this.space();
  print(node.handler);
  if (node.finalizer) {
    this.space();
    this.push("finally ");
    print(node.finalizer);
  }
};
 
exports.CatchClause = function (node, print) {
  this.keyword("catch");
  this.push("(");
  print(node.param);
  this.push(") ");
  print(node.body);
};
 
exports.ThrowStatement = function (node, print) {
  this.push("throw ");
  print(node.argument);
  this.semicolon();
};
 
exports.SwitchStatement = function (node, print) {
  this.keyword("switch");
  this.push("(");
  print(node.discriminant);
  this.push(") {");
  print.sequence(node.cases, { indent: true });
  this.push("}");
};
 
exports.SwitchCase = function (node, print) {
  if (node.test) {
    this.push("case ");
    print(node.test);
    this.push(":");
  } else {
    this.push("default:");
  }
 
  this.newline();
  print.sequence(node.consequent, { indent: true });
};
 
exports.DebuggerStatement = function () {
  this.push("debugger;");
};
 
exports.VariableDeclaration = function (node, print, parent) {
  this.push(node.kind + " ");
 
  var inits = 0;
  var noInits = 0;
  for (var i in node.declarations) {
    if (node.declarations[i].init) {
      inits++;
    } else {
      noInits++;
    }
  }
 
  var sep = ",";
  if (inits > noInits) { // more inits than noinits
    sep += "\n" + util.repeat(node.kind.length + 1);
  } else {
    sep += " ";
  }
 
  print.join(node.declarations, { separator: sep });
 
  if (!t.isFor(parent)) {
    this.semicolon();
  }
};
 
exports.PrivateDeclaration = function (node, print) {
  this.push("private ");
  print.join(node.declarations, { separator: ", " });
  this.semicolon();
};
 
exports.VariableDeclarator = function (node, print) {
  if (node.init) {
    print(node.id);
    this.push(" = ");
    print(node.init);
  } else {
    print(node.id);
  }
};