Sha256: e57d88a0a5507e60dcbc3d3981268d188b2a16a13bbc3947a6df331515d0dacd

Contents?: true

Size: 1.5 KB

Versions: 5

Compression:

Stored size: 1.5 KB

Contents

"use strict";

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

function _sortBy() {
  const data = _interopRequireDefault(require("lodash/sortBy"));

  _sortBy = function () {
    return data;
  };

  return data;
}

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

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

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 = (0, _sortBy().default)(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

5 entries across 5 versions & 2 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/@babel/core/lib/transformation/block-hoist-plugin.js
tang-0.2.1 spec/tang_app/node_modules/@babel/core/lib/transformation/block-hoist-plugin.js
tang-0.2.0 spec/tang_app/node_modules/@babel/core/lib/transformation/block-hoist-plugin.js
tang-0.1.0 spec/tang_app/node_modules/@babel/core/lib/transformation/block-hoist-plugin.js
tang-0.0.9 spec/tang_app/node_modules/@babel/core/lib/transformation/block-hoist-plugin.js