index.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.compilePseudoSelector = exports.aliases = exports.pseudos = exports.filters = void 0;
  4. var css_what_1 = require("css-what");
  5. var filters_js_1 = require("./filters.js");
  6. Object.defineProperty(exports, "filters", { enumerable: true, get: function () { return filters_js_1.filters; } });
  7. var pseudos_js_1 = require("./pseudos.js");
  8. Object.defineProperty(exports, "pseudos", { enumerable: true, get: function () { return pseudos_js_1.pseudos; } });
  9. var aliases_js_1 = require("./aliases.js");
  10. Object.defineProperty(exports, "aliases", { enumerable: true, get: function () { return aliases_js_1.aliases; } });
  11. var subselects_js_1 = require("./subselects.js");
  12. function compilePseudoSelector(next, selector, options, context, compileToken) {
  13. var _a;
  14. var name = selector.name, data = selector.data;
  15. if (Array.isArray(data)) {
  16. if (!(name in subselects_js_1.subselects)) {
  17. throw new Error("Unknown pseudo-class :".concat(name, "(").concat(data, ")"));
  18. }
  19. return subselects_js_1.subselects[name](next, data, options, context, compileToken);
  20. }
  21. var userPseudo = (_a = options.pseudos) === null || _a === void 0 ? void 0 : _a[name];
  22. var stringPseudo = typeof userPseudo === "string" ? userPseudo : aliases_js_1.aliases[name];
  23. if (typeof stringPseudo === "string") {
  24. if (data != null) {
  25. throw new Error("Pseudo ".concat(name, " doesn't have any arguments"));
  26. }
  27. // The alias has to be parsed here, to make sure options are respected.
  28. var alias = (0, css_what_1.parse)(stringPseudo);
  29. return subselects_js_1.subselects["is"](next, alias, options, context, compileToken);
  30. }
  31. if (typeof userPseudo === "function") {
  32. (0, pseudos_js_1.verifyPseudoArgs)(userPseudo, name, data, 1);
  33. return function (elem) { return userPseudo(elem, data) && next(elem); };
  34. }
  35. if (name in filters_js_1.filters) {
  36. return filters_js_1.filters[name](next, data, options, context);
  37. }
  38. if (name in pseudos_js_1.pseudos) {
  39. var pseudo_1 = pseudos_js_1.pseudos[name];
  40. (0, pseudos_js_1.verifyPseudoArgs)(pseudo_1, name, data, 2);
  41. return function (elem) { return pseudo_1(elem, options, data) && next(elem); };
  42. }
  43. throw new Error("Unknown pseudo-class :".concat(name));
  44. }
  45. exports.compilePseudoSelector = compilePseudoSelector;
  46. //# sourceMappingURL=index.js.map