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

Statements: 100% (119 / 119)      Branches: 95% (19 / 20)      Functions: 100% (18 / 18)      Lines: 100% (118 / 118)      Ignored: none     

All files » 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 1761   1 2 2 2 2 2     1 143 143 143 143   143   143 18 18 18       1 49 49   49 49   49 42 42   49   49 25 25     49 49     1 107 107 107 107 107     1 2 36 36 36 36 36 36 36       1 1   1 5 5 5 5 5 5 5     1 3 824   824 824 716 716     824       1 1 1   1 9 9 9     1 17 17 17 17 17 5 5 5       1 16 16 16 16 16     1 18 18 18     1 109 109 109 109 109 109     1 616 609 609 609   7     616 616     1 1     1 847   847   847 769       1 914 781 781 781   133      
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();
  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.space();
  print.sequence(node.consequent, { indent: true });
};
 
exports.DebuggerStatement = function () {
  this.push("debugger;");
};
 
exports.VariableDeclaration = function (node, print, parent) {
  this.push(node.kind + " ");
 
  print.join(node.declarations, { separator: ", " });
 
  if (!t.isFor(parent)) {
    this.semicolon();
  }
};
 
exports.VariableDeclarator = function (node, print) {
  if (node.init) {
    print(node.id);
    this.push(" = ");
    print(node.init);
  } else {
    print(node.id);
  }
};