css-select
Advanced tools
Comparing version 5.0.0 to 5.0.1
@@ -19,10 +19,22 @@ import boolbase from "boolbase"; | ||
} | ||
const is = (next, token, options, context, compileToken) => { | ||
const opts = { | ||
function copyOptions(options) { | ||
// Not copied: context, rootFunc | ||
return { | ||
xmlMode: !!options.xmlMode, | ||
lowerCaseAttributeNames: !!options.lowerCaseAttributeNames, | ||
lowerCaseTags: !!options.lowerCaseTags, | ||
quirksMode: !!options.quirksMode, | ||
cacheResults: !!options.cacheResults, | ||
pseudos: options.pseudos, | ||
adapter: options.adapter, | ||
equals: options.equals, | ||
}; | ||
const func = compileToken(token, opts, context); | ||
return (elem) => func(elem) && next(elem); | ||
} | ||
const is = (next, token, options, context, compileToken) => { | ||
const func = compileToken(token, copyOptions(options), context); | ||
return func === boolbase.trueFunc | ||
? next | ||
: func === boolbase.falseFunc | ||
? boolbase.falseFunc | ||
: (elem) => func(elem) && next(elem); | ||
}; | ||
@@ -42,23 +54,11 @@ /* | ||
not(next, token, options, context, compileToken) { | ||
const opts = { | ||
xmlMode: !!options.xmlMode, | ||
adapter: options.adapter, | ||
equals: options.equals, | ||
}; | ||
const func = compileToken(token, opts, context); | ||
if (func === boolbase.falseFunc) | ||
return next; | ||
if (func === boolbase.trueFunc) | ||
return boolbase.falseFunc; | ||
return function not(elem) { | ||
return !func(elem) && next(elem); | ||
}; | ||
const func = compileToken(token, copyOptions(options), context); | ||
return func === boolbase.falseFunc | ||
? next | ||
: func === boolbase.trueFunc | ||
? boolbase.falseFunc | ||
: (elem) => !func(elem) && next(elem); | ||
}, | ||
has(next, subselect, options, _context, compileToken) { | ||
const { adapter } = options; | ||
const opts = { | ||
xmlMode: !!options.xmlMode, | ||
adapter, | ||
equals: options.equals, | ||
}; | ||
// @ts-expect-error Uses an array as a pointer to the current element (side effects) | ||
@@ -68,3 +68,3 @@ const context = subselect.some((s) => s.some(isTraversal)) | ||
: undefined; | ||
const compiled = compileToken(subselect, opts, context); | ||
const compiled = compileToken(subselect, copyOptions(options), context); | ||
if (compiled === boolbase.falseFunc) | ||
@@ -76,9 +76,11 @@ return boolbase.falseFunc; | ||
const hasElement = ensureIsTag(compiled, adapter); | ||
const { shouldTestNextSiblings = false } = compiled; | ||
/* | ||
* `shouldTestNextSiblings` will only be true if the query starts with | ||
* a traversal (sibling or adjacent). That means we will always have a context. | ||
*/ | ||
if (context) { | ||
/* | ||
* `shouldTestNextSiblings` will only be true if the query starts with | ||
* a traversal (sibling or adjacent). That means we will always have a context. | ||
*/ | ||
const { shouldTestNextSiblings = false } = compiled; | ||
return (elem) => { | ||
if (!next(elem)) | ||
return false; | ||
context[0] = elem; | ||
@@ -89,3 +91,3 @@ const childs = adapter.getChildren(elem); | ||
: childs; | ||
return (next(elem) && adapter.existsOne(hasElement, nextElements)); | ||
return adapter.existsOne(hasElement, nextElements); | ||
}; | ||
@@ -92,0 +94,0 @@ } |
@@ -118,3 +118,3 @@ import type { Selector } from "css-what"; | ||
*/ | ||
pseudos?: Record<string, string | ((elem: ElementNode, value?: string | null) => boolean)>; | ||
pseudos?: Record<string, string | ((elem: ElementNode, value?: string | null) => boolean)> | undefined; | ||
/** | ||
@@ -121,0 +121,0 @@ * The last function in the stack, will be called with the last element |
@@ -36,10 +36,22 @@ "use strict"; | ||
exports.getNextSiblings = getNextSiblings; | ||
var is = function (next, token, options, context, compileToken) { | ||
var opts = { | ||
function copyOptions(options) { | ||
// Not copied: context, rootFunc | ||
return { | ||
xmlMode: !!options.xmlMode, | ||
lowerCaseAttributeNames: !!options.lowerCaseAttributeNames, | ||
lowerCaseTags: !!options.lowerCaseTags, | ||
quirksMode: !!options.quirksMode, | ||
cacheResults: !!options.cacheResults, | ||
pseudos: options.pseudos, | ||
adapter: options.adapter, | ||
equals: options.equals, | ||
}; | ||
var func = compileToken(token, opts, context); | ||
return function (elem) { return func(elem) && next(elem); }; | ||
} | ||
var is = function (next, token, options, context, compileToken) { | ||
var func = compileToken(token, copyOptions(options), context); | ||
return func === boolbase_1.default.trueFunc | ||
? next | ||
: func === boolbase_1.default.falseFunc | ||
? boolbase_1.default.falseFunc | ||
: function (elem) { return func(elem) && next(elem); }; | ||
}; | ||
@@ -59,23 +71,11 @@ /* | ||
not: function (next, token, options, context, compileToken) { | ||
var opts = { | ||
xmlMode: !!options.xmlMode, | ||
adapter: options.adapter, | ||
equals: options.equals, | ||
}; | ||
var func = compileToken(token, opts, context); | ||
if (func === boolbase_1.default.falseFunc) | ||
return next; | ||
if (func === boolbase_1.default.trueFunc) | ||
return boolbase_1.default.falseFunc; | ||
return function not(elem) { | ||
return !func(elem) && next(elem); | ||
}; | ||
var func = compileToken(token, copyOptions(options), context); | ||
return func === boolbase_1.default.falseFunc | ||
? next | ||
: func === boolbase_1.default.trueFunc | ||
? boolbase_1.default.falseFunc | ||
: function (elem) { return !func(elem) && next(elem); }; | ||
}, | ||
has: function (next, subselect, options, _context, compileToken) { | ||
var adapter = options.adapter; | ||
var opts = { | ||
xmlMode: !!options.xmlMode, | ||
adapter: adapter, | ||
equals: options.equals, | ||
}; | ||
// @ts-expect-error Uses an array as a pointer to the current element (side effects) | ||
@@ -87,3 +87,3 @@ var context = subselect.some(function (s) { | ||
: undefined; | ||
var compiled = compileToken(subselect, opts, context); | ||
var compiled = compileToken(subselect, copyOptions(options), context); | ||
if (compiled === boolbase_1.default.falseFunc) | ||
@@ -97,14 +97,16 @@ return boolbase_1.default.falseFunc; | ||
var hasElement = ensureIsTag(compiled, adapter); | ||
var _a = compiled.shouldTestNextSiblings, shouldTestNextSiblings = _a === void 0 ? false : _a; | ||
/* | ||
* `shouldTestNextSiblings` will only be true if the query starts with | ||
* a traversal (sibling or adjacent). That means we will always have a context. | ||
*/ | ||
if (context) { | ||
/* | ||
* `shouldTestNextSiblings` will only be true if the query starts with | ||
* a traversal (sibling or adjacent). That means we will always have a context. | ||
*/ | ||
var _a = compiled.shouldTestNextSiblings, shouldTestNextSiblings_1 = _a === void 0 ? false : _a; | ||
return function (elem) { | ||
if (!next(elem)) | ||
return false; | ||
context[0] = elem; | ||
var childs = adapter.getChildren(elem); | ||
var nextElements = shouldTestNextSiblings | ||
var nextElements = shouldTestNextSiblings_1 | ||
? __spreadArray(__spreadArray([], childs, true), getNextSiblings(elem, adapter), true) : childs; | ||
return (next(elem) && adapter.existsOne(hasElement, nextElements)); | ||
return adapter.existsOne(hasElement, nextElements); | ||
}; | ||
@@ -111,0 +113,0 @@ } |
@@ -118,3 +118,3 @@ import type { Selector } from "css-what"; | ||
*/ | ||
pseudos?: Record<string, string | ((elem: ElementNode, value?: string | null) => boolean)>; | ||
pseudos?: Record<string, string | ((elem: ElementNode, value?: string | null) => boolean)> | undefined; | ||
/** | ||
@@ -121,0 +121,0 @@ * The last function in the stack, will be called with the last element |
{ | ||
"name": "css-select", | ||
"version": "5.0.0", | ||
"version": "5.0.1", | ||
"description": "a CSS selector compiler/engine", | ||
@@ -5,0 +5,0 @@ "author": "Felix Boehm <me@feedic.com>", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
221521
2778