[79a0317] | 1 | "use strict";
|
---|
| 2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
| 3 | exports.compilePseudoSelector = exports.aliases = exports.pseudos = exports.filters = void 0;
|
---|
| 4 | /*
|
---|
| 5 | * Pseudo selectors
|
---|
| 6 | *
|
---|
| 7 | * Pseudo selectors are available in three forms:
|
---|
| 8 | *
|
---|
| 9 | * 1. Filters are called when the selector is compiled and return a function
|
---|
| 10 | * that has to return either false, or the results of `next()`.
|
---|
| 11 | * 2. Pseudos are called on execution. They have to return a boolean.
|
---|
| 12 | * 3. Subselects work like filters, but have an embedded selector that will be run separately.
|
---|
| 13 | *
|
---|
| 14 | * Filters are great if you want to do some pre-processing, or change the call order
|
---|
| 15 | * of `next()` and your code.
|
---|
| 16 | * Pseudos should be used to implement simple checks.
|
---|
| 17 | */
|
---|
| 18 | var boolbase_1 = require("boolbase");
|
---|
| 19 | var css_what_1 = require("css-what");
|
---|
| 20 | var filters_1 = require("./filters");
|
---|
| 21 | Object.defineProperty(exports, "filters", { enumerable: true, get: function () { return filters_1.filters; } });
|
---|
| 22 | var pseudos_1 = require("./pseudos");
|
---|
| 23 | Object.defineProperty(exports, "pseudos", { enumerable: true, get: function () { return pseudos_1.pseudos; } });
|
---|
| 24 | var aliases_1 = require("./aliases");
|
---|
| 25 | Object.defineProperty(exports, "aliases", { enumerable: true, get: function () { return aliases_1.aliases; } });
|
---|
| 26 | var subselects_1 = require("./subselects");
|
---|
| 27 | function compilePseudoSelector(next, selector, options, context, compileToken) {
|
---|
| 28 | var name = selector.name, data = selector.data;
|
---|
| 29 | if (Array.isArray(data)) {
|
---|
| 30 | return subselects_1.subselects[name](next, data, options, context, compileToken);
|
---|
| 31 | }
|
---|
| 32 | if (name in aliases_1.aliases) {
|
---|
| 33 | if (data != null) {
|
---|
| 34 | throw new Error("Pseudo ".concat(name, " doesn't have any arguments"));
|
---|
| 35 | }
|
---|
| 36 | // The alias has to be parsed here, to make sure options are respected.
|
---|
| 37 | var alias = (0, css_what_1.parse)(aliases_1.aliases[name]);
|
---|
| 38 | return subselects_1.subselects.is(next, alias, options, context, compileToken);
|
---|
| 39 | }
|
---|
| 40 | if (name in filters_1.filters) {
|
---|
| 41 | return filters_1.filters[name](next, data, options, context);
|
---|
| 42 | }
|
---|
| 43 | if (name in pseudos_1.pseudos) {
|
---|
| 44 | var pseudo_1 = pseudos_1.pseudos[name];
|
---|
| 45 | (0, pseudos_1.verifyPseudoArgs)(pseudo_1, name, data);
|
---|
| 46 | return pseudo_1 === boolbase_1.falseFunc
|
---|
| 47 | ? boolbase_1.falseFunc
|
---|
| 48 | : next === boolbase_1.trueFunc
|
---|
| 49 | ? function (elem) { return pseudo_1(elem, options, data); }
|
---|
| 50 | : function (elem) { return pseudo_1(elem, options, data) && next(elem); };
|
---|
| 51 | }
|
---|
| 52 | throw new Error("unmatched pseudo-class :".concat(name));
|
---|
| 53 | }
|
---|
| 54 | exports.compilePseudoSelector = compilePseudoSelector;
|
---|