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

Statements: 100% (18 / 18)      Branches: 100% (4 / 4)      Functions: 100% (4 / 4)      Lines: 100% (17 / 17)      Ignored: none     

All files » 6to5/lib/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 421   1 8 8   8 8   8         8 5         3       1 6 6 6         6   6     4        
var t = require("../../types");
 
exports.BindMemberExpression = function (node, parent, file, scope) {
  var object = node.object;
  var prop   = node.property;
 
  var temp = scope.generateTempBasedOnNode(node.object, file);
  if (temp) object = temp;
 
  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))
    ]));
  };
 
  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);
    }))
  ]);
};