Code coverage report for 6to5/transformers/arrow-functions.js

Statements: 100% (25 / 25)      Branches: 100% (13 / 13)      Functions: 100% (4 / 4)      Lines: 100% (24 / 24)      Ignored: none     

All files » 6to5/transformers/ » arrow-functions.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 501 1 1   1 16   16 16   16 1       15       1   71 71     71 661       4 7   3 3 3       4     71 3 3          
var traverse = require("../traverse");
var util     = require("../util");
var b        = require("ast-types").builders;
 
exports.ArrowFunctionExpression = function (node) {
  util.ensureBlock(node);
 
  node.expression = false;
  node.type = "FunctionExpression";
 
  if (traverse.hasType(node, "ThisExpression")) {
    return util.template("function-bind-this", {
      FUNCTION: node
    });
  } else {
    return node;
  }
};
 
exports.FunctionDeclaration =
exports.FunctionExpression = function (node, parent, opts, generateUid) {
  var hasArguments = false;
  var id;
 
  // traverse the function and find all arrow functions
  traverse(node, function (node) {
    if (node.type !== "ArrowFunctionExpression") return;
 
    // traverse all child nodes of this arrow function and find a sole arguments
    // identifier
    traverse(node, function (node, parent) {
      if (node.type === "Identifier" && node.name === "arguments" &&
          parent.type !== "MemberExpression") {
        hasArguments = true;
        id = id || b.identifier(generateUid("arguments"));
        return id;
      }
    }, traverse.FUNCTION_TYPES);
 
    return false;
  }, ["FunctionDeclaration", "FunctionExpression"]);
 
  if (hasArguments) {
    util.ensureBlock(node);
    node.body.body.unshift(b.variableDeclaration("var", [
      b.variableDeclarator(id, b.identifier("arguments"))
    ]));
  }
};