Code coverage report for 6to5/lib/6to5/transformation/transformers/es6-for-of.js

Statements: 100% (19 / 19)      Branches: 100% (6 / 6)      Functions: 100% (1 / 1)      Lines: 100% (19 / 19)      Ignored: none     

All files » 6to5/lib/6to5/transformation/transformers/ » es6-for-of.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 361 1   1 22 22   22 22   22 1 21 20       1     21           21 21   21 21 21   21    
var util = require("../../util");
var t    = require("../../types");
 
exports.ForOfStatement = function (node, parent, file, scope) {
  var left = node.left;
  var declar;
 
  var stepKey   = file.generateUidIdentifier("step", scope);
  var stepValue = t.memberExpression(stepKey, t.identifier("value"));
 
  if (t.isIdentifier(left) || t.isPattern(left)) {
    declar = t.expressionStatement(t.assignmentExpression("=", left, stepValue));
  } else if (t.isVariableDeclaration(left)) {
    declar = t.variableDeclaration(left.kind, [
      t.variableDeclarator(left.declarations[0].id, stepValue)
    ]);
  } else {
    throw file.errorWithNode(left, "Unknown node type " + left.type + " in ForOfStatement");
  }
 
  var node2 = util.template("for-of", {
    ITERATOR_KEY: file.generateUidIdentifier("iterator", scope),
    STEP_KEY:     stepKey,
    OBJECT:       node.right
  });
 
  t.inheritsComments(node2, node);
  t.ensureBlock(node);
 
  var block = node2.body;
  block.body.push(declar);
  block.body = block.body.concat(node.body.body);
 
  return node2;
};