import remapAsyncToGenerator from "../../helpers/remap-async-to-generator";
import * as t from "../../../types";

/**
 * [Please add a description.]
 */

export function manipulateOptions(opts) {
  opts.blacklist.push("regenerator");
}

export var metadata = {
  optional: true,
  dependencies: ["es7.asyncFunctions", "es6.classes"]
};

/**
 * [Please add a description.]
 */

export var visitor = {

  /**
   * [Please add a description.]
   */

  Function(node, parent, scope, file) {
    if (!node.async || node.generator) return;

    return remapAsyncToGenerator(
      this,
      t.memberExpression(file.addImport("bluebird", null, "absolute"), t.identifier("coroutine"))
    );
  }
};
