<commit_before>var babel                = require("../lib/api/node");
var buildExternalHelpers = require("../lib/tools/build-external-helpers");
var Pipeline             = require("../lib/transformation/pipeline");
var sourceMap            = require("source-map");
var assert               = require("assert");
var File                 = require("../lib/transformation/file").default;
var Plugin               = require("../lib/transformation/plugin");

function assertIgnored(result) {
  assert.ok(result.ignored);
}

function assertNotIgnored(result) {
  assert.ok(!result.ignored);
}

// shim
function transformAsync(code, opts) {
  return {
    then: function (resolve) {
      resolve(babel.transform(code, opts));
    }
  };
}

suite("api", function () {
  test("transformFile", function (done) {
    babel.transformFile(__dirname + "/fixtures/api/file.js", {}, function (err, res) {
      if (err) return done(err);
      assert.equal(res.code, "foo();");
      done();
    });
  });

  test("transformFileSync", function () {
    assert.equal(babel.transformFileSync(__dirname + "/fixtures/api/file.js", {}).code, "foo();");
  });

  test("options merge backwards", function () {
    return transformAsync("", {
      presets: [__dirname + "/../../babel-preset-es2015"],
      plugins: [__dirname + "/../../babel-plugin-syntax-jsx"]
    }).then(function (result) {
      assert.ok(result.options.plugins[0][0].manipulateOptions.toString().indexOf("jsx") >= 0);
    });
  });

  test("pass per preset", function () {
    var aliasBaseType = null;

    function execTest(passPerPreset) {
      return babel.transform('type Foo = number; let x = (y): Foo => y;', {
        passPerPreset: passPerPreset,
        presets: [
          // First preset with our plugin, "before"
          {
            plugins: [
              new Plugin({
                visitor: {
                  Function(path) {
                    var node = path.node;
                    var scope = path.scope;

                    var alias = scope
                      .getProgramParent()
                      .getBinding(node.returnType.typeAnnotation.id.name)<commit_msg>Pass per preset: Use full function systax in test for old Node versions<commit_after>var babel                = require("../lib/api/node");
var buildExternalHelpers = require("../lib/tools/build-external-helpers");
var Pipeline             = require("../lib/transformation/pipeline");
var sourceMap            = require("source-map");
var assert               = require("assert");
var File                 = require("../lib/transformation/file").default;
var Plugin               = require("../lib/transformation/plugin");

function assertIgnored(result) {
  assert.ok(result.ignored);
}

function assertNotIgnored(result) {
  assert.ok(!result.ignored);
}

// shim
function transformAsync(code, opts) {
  return {
    then: function (resolve) {
      resolve(babel.transform(code, opts));
    }
  };
}

suite("api", function () {
  test("transformFile", function (done) {
    babel.transformFile(__dirname + "/fixtures/api/file.js", {}, function (err, res) {
      if (err) return done(err);
      assert.equal(res.code, "foo();");
      done();
    });
  });

  test("transformFileSync", function () {
    assert.equal(babel.transformFileSync(__dirname + "/fixtures/api/file.js", {}).code, "foo();");
  });

  test("options merge backwards", function () {
    return transformAsync("", {
      presets: [__dirname + "/../../babel-preset-es2015"],
      plugins: [__dirname + "/../../babel-plugin-syntax-jsx"]
    }).then(function (result) {
      assert.ok(result.options.plugins[0][0].manipulateOptions.toString().indexOf("jsx") >= 0);
    });
  });

  test("pass per preset", function () {
    var aliasBaseType = null;

    function execTest(passPerPreset) {
      return babel.transform('type Foo = number; let x = (y): Foo => y;', {
        passPerPreset: passPerPreset,
        presets: [
          // First preset with our plugin, "before"
          {
            plugins: [
              new Plugin({
                visitor: {
                  Function: function(path) {
                    var node = path.node;
                    var scope = path.scope;

                    var alias = scope
                      .getProgramParent()
                      .getBinding(node.returnType.typeAnnotation.id.name)
{'fraction_non_alphanumeric': 0.1585198720877113, 'fraction_numerical': 0.0031978072179077205, 'mean_word_length': 2.272795216741405, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7197679', 'n_tokens_mistral': 1274, 'n_tokens_neox': 1226, 'n_words': 250}