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

Statements: 100% (136 / 136)      Branches: 96.15% (25 / 26)      Functions: 100% (19 / 19)      Lines: 100% (135 / 135)      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 200 201 202 203 204 205 206 207 208 2091 1   1 2 2 2 2 2     1 376 376 376 376   376   376 106 106 106       1 75 75   75 75   75 63 63   75   75 30 30     75 75     1 9 9 9 9 9     1 2 52 52 52 52 52 52 52       1 1   1 3 3 3 3 3 3 3     1 3 620   620 620 570 570     620       1 1 1   1 6 6 6     1 14 14 14         14 3   11     14 5 5 5       1 13 13 13 13 13     1 37 37 37     1 11 11 11 11 11 11     1 28 22 22 22   6     28 28     1 1     1 1237   1237 1237 1237 1345 1171   174       1237 1237 1110   127     1237   1237 1115       1 4 4 4     1 1345 1171 1171 1171   174      
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) {
    Eif (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();
 
  // Esprima bug puts the catch clause in a `handlers` array.
  // see https://code.google.com/p/esprima/issues/detail?id=433
  // We run into this from regenerator generated ast.
  if (node.handlers) {
    print(node.handlers[0]);
  } else {
    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);
  }
};