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

Statements: 20% (4 / 20)      Branches: 0% (0 / 8)      Functions: 0% (0 / 1)      Lines: 21.05% (4 / 19)      Ignored: none     

All files » 6to5/lib/6to5/transformation/transformers/ » optional-for-of-fast.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 381 1   1   1                                                                
var util = require("../../util");
var t    = require("../../types");
 
exports.optional = true;
 
exports.ForOfStatement = function (node, parent, file, scope) {
  var left = node.left;
  var declar, id;
 
  if (t.isIdentifier(left) || t.isPattern(left)) {
    id = left;
  } else if (t.isVariableDeclaration(left)) {
    id = left.declarations[0].id;
    declar = t.variableDeclaration(left.kind, [
      t.variableDeclarator(id)
    ]);
  } else {
    throw file.errorWithNode(left, "Unknown node type " + left.type + " in ForOfStatement");
  }
 
  var node2 = util.template("for-of-fast", {
    LOOP_OBJECT:  file.generateUidIdentifier("loopObject", scope),
    IS_ARRAY:     file.generateUidIdentifier("isArray", scope),
    OBJECT:       node.right,
    INDEX:        file.generateUidIdentifier("i", scope),
    ID:           id
  });
 
  t.inheritsComments(node2, node);
  t.ensureBlock(node);
 
  var block = node2.body;
  if (declar) block.body.unshift(declar);
  block.body = block.body.concat(node.body.body);
 
  return node2;
};