Code coverage report for 6to5/transformation/transformers/playground-method-binding.js

Statements: 100% (21 / 21)      Branches: 100% (6 / 6)      Functions: 100% (4 / 4)      Lines: 100% (21 / 21)      Ignored: none     

All files » 6to5/transformation/transformers/ » playground-method-binding.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 491 1   1 8 8   8 8 1     8         8 1         7       1 6 6 6         6 2   2     2       4      
var t = require("../../types");
var _ = require("lodash");
 
exports.BindMemberExpression = function (node, parent, file, scope) {
  var object = node.object;
  var prop   = node.property;
 
  var temp;
  if (t.isDynamic(object)) {
    temp = object = scope.generateTemp(file);
  }
 
  var call = t.callExpression(
    t.memberExpression(t.memberExpression(object, prop), t.identifier("bind")),
    [object].concat(node.arguments)
  );
 
  if (temp) {
    return t.sequenceExpression([
      t.assignmentExpression("=", temp, node.object),
      call
    ]);
  } else {
    return call;
  }
};
 
exports.BindFunctionExpression = function (node, parent, file, scope) {
  var buildCall = function (args) {
    var param = file.generateUidIdentifier("val", scope);
    return t.functionExpression(null, [param], t.blockStatement([
      t.returnStatement(t.callExpression(t.memberExpression(param, node.callee), args))
    ]));
  };
 
  if (_.find(node.arguments, t.isDynamic)) {
    var temp = scope.generateTemp(file, "args");
 
    return t.sequenceExpression([
      t.assignmentExpression("=", temp, t.arrayExpression(node.arguments)),
      buildCall(node.arguments.map(function (node, i) {
        return t.memberExpression(temp, t.literal(i), true);
      }))
    ]);
  } else {
    return buildCall(node.arguments);
  }
};