Sha256: f18712b9ff2b30ebae155ffc0fc7bc1ff0cc38ea41f03d808e129c6770aaf87d

Contents?: true

Size: 1.38 KB

Versions: 4

Compression:

Stored size: 1.38 KB

Contents

"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = loadBlockHoistPlugin;

var _config = _interopRequireDefault(require("../config"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

const sortBy = require("lodash/sortBy");

let LOADED_PLUGIN;

function loadBlockHoistPlugin() {
  if (!LOADED_PLUGIN) {
    const config = _config.default.sync({
      babelrc: false,
      configFile: false,
      plugins: [blockHoistPlugin]
    });

    LOADED_PLUGIN = config ? config.passes[0][0] : undefined;
    if (!LOADED_PLUGIN) throw new Error("Assertion failure");
  }

  return LOADED_PLUGIN;
}

const blockHoistPlugin = {
  name: "internal.blockHoist",
  visitor: {
    Block: {
      exit({
        node
      }) {
        let hasChange = false;

        for (let i = 0; i < node.body.length; i++) {
          const bodyNode = node.body[i];

          if ((bodyNode == null ? void 0 : bodyNode._blockHoist) != null) {
            hasChange = true;
            break;
          }
        }

        if (!hasChange) return;
        node.body = sortBy(node.body, function (bodyNode) {
          let priority = bodyNode == null ? void 0 : bodyNode._blockHoist;
          if (priority == null) priority = 1;
          if (priority === true) priority = 2;
          return -1 * priority;
        });
      }

    }
  }
};

Version data entries

4 entries across 3 versions & 2 rubygems

Version Path
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/@babel/core/lib/transformation/block-hoist-plugin.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/@babel/core/lib/transformation/block-hoist-plugin.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/@babel/core/lib/transformation/block-hoist-plugin.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/@babel/core/lib/transformation/block-hoist-plugin.js