public_library_map/node_modules/css-select/lib/pseudo-selectors/index.js

46 lines
2.4 KiB
JavaScript
Raw Normal View History

2021-11-24 19:46:47 +11:00
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.compilePseudoSelector = exports.aliases = exports.pseudos = exports.filters = void 0;
var css_what_1 = require("css-what");
2022-09-03 17:12:22 +10:00
var filters_js_1 = require("./filters.js");
Object.defineProperty(exports, "filters", { enumerable: true, get: function () { return filters_js_1.filters; } });
var pseudos_js_1 = require("./pseudos.js");
Object.defineProperty(exports, "pseudos", { enumerable: true, get: function () { return pseudos_js_1.pseudos; } });
var aliases_js_1 = require("./aliases.js");
Object.defineProperty(exports, "aliases", { enumerable: true, get: function () { return aliases_js_1.aliases; } });
var subselects_js_1 = require("./subselects.js");
2021-11-24 19:46:47 +11:00
function compilePseudoSelector(next, selector, options, context, compileToken) {
2022-09-03 17:12:22 +10:00
var _a;
2021-11-24 19:46:47 +11:00
var name = selector.name, data = selector.data;
if (Array.isArray(data)) {
2022-09-03 17:12:22 +10:00
if (!(name in subselects_js_1.subselects)) {
throw new Error("Unknown pseudo-class :".concat(name, "(").concat(data, ")"));
}
return subselects_js_1.subselects[name](next, data, options, context, compileToken);
2021-11-24 19:46:47 +11:00
}
2022-09-03 17:12:22 +10:00
var userPseudo = (_a = options.pseudos) === null || _a === void 0 ? void 0 : _a[name];
var stringPseudo = typeof userPseudo === "string" ? userPseudo : aliases_js_1.aliases[name];
if (typeof stringPseudo === "string") {
2021-11-24 19:46:47 +11:00
if (data != null) {
2022-09-03 17:12:22 +10:00
throw new Error("Pseudo ".concat(name, " doesn't have any arguments"));
2021-11-24 19:46:47 +11:00
}
// The alias has to be parsed here, to make sure options are respected.
2022-09-03 17:12:22 +10:00
var alias = (0, css_what_1.parse)(stringPseudo);
return subselects_js_1.subselects["is"](next, alias, options, context, compileToken);
}
if (typeof userPseudo === "function") {
(0, pseudos_js_1.verifyPseudoArgs)(userPseudo, name, data, 1);
return function (elem) { return userPseudo(elem, data) && next(elem); };
2021-11-24 19:46:47 +11:00
}
2022-09-03 17:12:22 +10:00
if (name in filters_js_1.filters) {
return filters_js_1.filters[name](next, data, options, context);
2021-11-24 19:46:47 +11:00
}
2022-09-03 17:12:22 +10:00
if (name in pseudos_js_1.pseudos) {
var pseudo_1 = pseudos_js_1.pseudos[name];
(0, pseudos_js_1.verifyPseudoArgs)(pseudo_1, name, data, 2);
return function (elem) { return pseudo_1(elem, options, data) && next(elem); };
2021-11-24 19:46:47 +11:00
}
2022-09-03 17:12:22 +10:00
throw new Error("Unknown pseudo-class :".concat(name));
2021-11-24 19:46:47 +11:00
}
exports.compilePseudoSelector = compilePseudoSelector;
2022-09-03 17:12:22 +10:00
//# sourceMappingURL=index.js.map