Sha256: 825c7888f12b9fce1fd0ed36628b3de8d23b9cee35cc6e485ff0f8b78188cd2f

Contents?: true

Size: 1.88 KB

Versions: 24

Compression:

Stored size: 1.88 KB

Contents

"use strict";

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

var _optionAssertions = require("./option-assertions");

const VALIDATORS = {
  name: _optionAssertions.assertString,
  manipulateOptions: _optionAssertions.assertFunction,
  pre: _optionAssertions.assertFunction,
  post: _optionAssertions.assertFunction,
  inherits: _optionAssertions.assertFunction,
  visitor: assertVisitorMap,
  parserOverride: _optionAssertions.assertFunction,
  generatorOverride: _optionAssertions.assertFunction
};

function assertVisitorMap(key, value) {
  const obj = (0, _optionAssertions.assertObject)(key, value);

  if (obj) {
    Object.keys(obj).forEach(prop => assertVisitorHandler(prop, obj[prop]));

    if (obj.enter || obj.exit) {
      throw new Error(`.${key} cannot contain catch-all "enter" or "exit" handlers. Please target individual nodes.`);
    }
  }

  return obj;
}

function assertVisitorHandler(key, value) {
  if (value && typeof value === "object") {
    Object.keys(value).forEach(handler => {
      if (handler !== "enter" && handler !== "exit") {
        throw new Error(`.visitor["${key}"] may only have .enter and/or .exit handlers.`);
      }
    });
  } else if (typeof value !== "function") {
    throw new Error(`.visitor["${key}"] must be a function`);
  }

  return value;
}

function validatePluginObject(obj) {
  const rootPath = {
    type: "root",
    source: "plugin"
  };
  Object.keys(obj).forEach(key => {
    const validator = VALIDATORS[key];
    const optLoc = {
      type: "option",
      name: key,
      parent: rootPath
    };
    if (validator) validator(optLoc, obj[key]);else {
      const invalidPluginPropertyError = new Error(`.${key} is not a valid Plugin property`);
      invalidPluginPropertyError.code = "BABEL_UNKNOWN_PLUGIN_PROPERTY";
      throw invalidPluginPropertyError;
    }
  });
  return obj;
}

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
trusty-cms-5.0.7 node_modules/@babel/core/lib/config/validation/plugins.js
trusty-cms-5.0.6 node_modules/@babel/core/lib/config/validation/plugins.js
trusty-cms-5.0.5 node_modules/@babel/core/lib/config/validation/plugins.js
trusty-cms-5.0.4 node_modules/@babel/core/lib/config/validation/plugins.js
trusty-cms-5.0.3 node_modules/@babel/core/lib/config/validation/plugins.js
trusty-cms-5.0.2 node_modules/@babel/core/lib/config/validation/plugins.js
trusty-cms-5.0.1 node_modules/@babel/core/lib/config/validation/plugins.js
trusty-cms-4.3.5 node_modules/@babel/core/lib/config/validation/plugins.js
trusty-cms-5.0.0 node_modules/@babel/core/lib/config/validation/plugins.js
trusty-cms-4.3.4 node_modules/@babel/core/lib/config/validation/plugins.js
trusty-cms-4.3.3 node_modules/@babel/core/lib/config/validation/plugins.js
trusty-cms-4.3.2 node_modules/@babel/core/lib/config/validation/plugins.js
trusty-cms-4.3.1 node_modules/@babel/core/lib/config/validation/plugins.js
trusty-cms-4.3 node_modules/@babel/core/lib/config/validation/plugins.js
trusty-cms-4.2.3 node_modules/@babel/core/lib/config/validation/plugins.js
trusty-cms-4.2.2 node_modules/@babel/core/lib/config/validation/plugins.js
trusty-cms-4.2.1 node_modules/@babel/core/lib/config/validation/plugins.js
trusty-cms-4.2 node_modules/@babel/core/lib/config/validation/plugins.js
trusty-cms-4.1.9 node_modules/@babel/core/lib/config/validation/plugins.js
trusty-cms-4.1.8 node_modules/@babel/core/lib/config/validation/plugins.js