Code coverage report for 6to5/lib/6to5/transformation/transformers/optional-bluebird-coroutines.js

Statements: 96% (24 / 25)      Branches: 90% (9 / 10)      Functions: 100% (4 / 4)      Lines: 100% (23 / 23)      Ignored: none     

All files » 6to5/lib/6to5/transformation/transformers/ » optional-bluebird-coroutines.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 441 1   1 4 4     1   1 4 4   4   30   30 4         4   4 2     2 2   2       1 4   2 2    
var traverse = require("../../traverse");
var t        = require("../../types");
 
exports.manipulateOptions = function (opts) {
  opts.experimental = true;
  opts.blacklist.push("generators");
};
 
exports.optional = true;
 
exports._Function = function (node, callId) {
  node.async = false;
  node.generator = true;
 
  traverse(node, {
    enter: function (node) {
      Iif (t.isFunction(node)) this.skip();
 
      if (t.isAwaitExpression(node)) {
        node.type = "YieldExpression";
      }
    }
  });
 
  var call = t.callExpression(callId, [node]);
 
  if (t.isFunctionDeclaration(node)) {
    var declar = t.variableDeclaration("var", [
      t.variableDeclarator(node.id, call)
    ]);
    declar._blockHoist = true;
    return declar;
  } else {
    return call;
  }
};
 
exports.Function = function (node, parent, file) {
  if (!node.async || node.generator) return;
 
  var id = file.addImport("bluebird");
  return exports._Function(node, t.memberExpression(id, t.identifier("coroutine")));
};