f70a166f08eca85f8fb08428b8868bbad03715348db90aced0521414f22af606cb4afb1e965c07c08235030d24927b735a79a19647170121a186b6e5fdc7c1 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.validatePluginObject = validatePluginObject;
  6. var _optionAssertions = require("./option-assertions.js");
  7. const VALIDATORS = {
  8. name: _optionAssertions.assertString,
  9. manipulateOptions: _optionAssertions.assertFunction,
  10. pre: _optionAssertions.assertFunction,
  11. post: _optionAssertions.assertFunction,
  12. inherits: _optionAssertions.assertFunction,
  13. visitor: assertVisitorMap,
  14. parserOverride: _optionAssertions.assertFunction,
  15. generatorOverride: _optionAssertions.assertFunction
  16. };
  17. function assertVisitorMap(loc, value) {
  18. const obj = (0, _optionAssertions.assertObject)(loc, value);
  19. if (obj) {
  20. Object.keys(obj).forEach(prop => {
  21. if (prop !== "_exploded" && prop !== "_verified") {
  22. assertVisitorHandler(prop, obj[prop]);
  23. }
  24. });
  25. if (obj.enter || obj.exit) {
  26. throw new Error(`${(0, _optionAssertions.msg)(loc)} cannot contain catch-all "enter" or "exit" handlers. Please target individual nodes.`);
  27. }
  28. }
  29. return obj;
  30. }
  31. function assertVisitorHandler(key, value) {
  32. if (value && typeof value === "object") {
  33. Object.keys(value).forEach(handler => {
  34. if (handler !== "enter" && handler !== "exit") {
  35. throw new Error(`.visitor["${key}"] may only have .enter and/or .exit handlers.`);
  36. }
  37. });
  38. } else if (typeof value !== "function") {
  39. throw new Error(`.visitor["${key}"] must be a function`);
  40. }
  41. }
  42. function validatePluginObject(obj) {
  43. const rootPath = {
  44. type: "root",
  45. source: "plugin"
  46. };
  47. Object.keys(obj).forEach(key => {
  48. const validator = VALIDATORS[key];
  49. if (validator) {
  50. const optLoc = {
  51. type: "option",
  52. name: key,
  53. parent: rootPath
  54. };
  55. validator(optLoc, obj[key]);
  56. } else {
  57. const invalidPluginPropertyError = new Error(`.${key} is not a valid Plugin property`);
  58. invalidPluginPropertyError.code = "BABEL_UNKNOWN_PLUGIN_PROPERTY";
  59. throw invalidPluginPropertyError;
  60. }
  61. });
  62. return obj;
  63. }
  64. 0 && 0;
  65. //# sourceMappingURL=plugins.js.map