Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@markuplint/selector

Package Overview
Dependencies
Maintainers
1
Versions
99
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@markuplint/selector - npm Package Compare versions

Comparing version 4.0.0-alpha.3 to 4.0.0-dev.28

7

lib/extended-selector/content-model-pseudo-class.js

@@ -10,3 +10,3 @@ import { contentModelCategoryToTagNames } from '@markuplint/ml-spec';

const matched = selectors
.map(selector => {
.flatMap(selector => {
if (selector === '#custom') {

@@ -41,3 +41,2 @@ // @ts-ignore

})
.flat()
.filter((m) => m.matched);

@@ -48,4 +47,4 @@ if (matched.length > 0) {

matched: true,
nodes: matched.map(m => (m.matched ? m.nodes : [])).flat(),
has: matched.map(m => (m.matched ? m.has : [])).flat(),
nodes: matched.flatMap(m => (m.matched ? m.nodes : [])),
has: matched.flatMap(m => (m.matched ? m.has : [])),
};

@@ -52,0 +51,0 @@ }

@@ -0,3 +1,13 @@

var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _SelectorTarget_combinedFrom, _SelectorTarget_selector;
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
import { isElement, isNonDocumentTypeChildNode, isPureHTMLElement } from './is.js';

@@ -181,3 +191,3 @@ import { regexSelectorMatches } from './regex-selector-matches.js';

const selectorAttrName = selector.attrName;
const matchedAttrNameList = Array.from(el.attributes).map(attr => {
const matchedAttrNameList = [...el.attributes].map(attr => {
const attrName = attr.name;

@@ -201,3 +211,3 @@ const matchedAttrName = regexSelectorMatches(selectorAttrName, attrName, isPureHTMLElement(el));

const selectorAttrValue = selector.attrValue;
const matchedAttrValueList = Array.from(el.attributes).map(attr => {
const matchedAttrValueList = [...el.attributes].map(attr => {
const attrName = attr.name;

@@ -220,3 +230,3 @@ const attrValue = attr.value;

}
const attrSelector = Array.from(specifiedAttr.entries())
const attrSelector = [...specifiedAttr.entries()]
.map(([name, value]) => {

@@ -223,0 +233,0 @@ return `[${name}${value ? `="${value}"` : ''}]`;

@@ -9,3 +9,4 @@ export function regexSelectorMatches(reg, raw, ignoreCase) {

}
matched.forEach((val, i) => (res[`$${i}`] = val));
for (const [i, val] of matched.entries())
res[`$${i}`] = val;
return {

@@ -17,3 +18,3 @@ ...res,

function toRegexp(pattern) {
const matched = pattern.match(/^\/(.+)\/([ig]*)$/i);
const matched = pattern.match(/^\/(.+)\/([gi]*)$/i);
if (matched && matched[1]) {

@@ -20,0 +21,0 @@ return new RegExp(matched[1], matched[2]);

@@ -0,3 +1,13 @@

var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _Selector_ruleset, _Ruleset_selectorGroup, _StructuredSelector_edge, _StructuredSelector_selector, _SelectorTarget_combinedFrom, _SelectorTarget_extended, _SelectorTarget_isAdded;
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
import { resolveNamespace } from '@markuplint/ml-spec';

@@ -48,7 +58,7 @@ import parser from 'postcss-selector-parser';

}
catch (e) {
if (e instanceof Error) {
catch (error) {
if (error instanceof Error) {
throw new InvalidSelectorError(selector);
}
throw e;
throw error;
}

@@ -62,9 +72,7 @@ return new Ruleset(selectors, extended, 0);

this.headCombinator = head?.headCombinator ?? null;
if (this.headCombinator) {
if (depth <= 0) {
if (__classPrivateFieldGet(this, _Ruleset_selectorGroup, "f")[0]?.selector) {
throw new InvalidSelectorError(__classPrivateFieldGet(this, _Ruleset_selectorGroup, "f")[0]?.selector);
}
throw new Error('Combinated selector depth is not expected');
if (this.headCombinator && depth <= 0) {
if (__classPrivateFieldGet(this, _Ruleset_selectorGroup, "f")[0]?.selector) {
throw new InvalidSelectorError(__classPrivateFieldGet(this, _Ruleset_selectorGroup, "f")[0]?.selector);
}
throw new Error('Combinated selector depth is not expected');
}

@@ -95,3 +103,3 @@ }

__classPrivateFieldGet(this, _StructuredSelector_selector, "f").nodes[0]?.type === 'combinator' ? __classPrivateFieldGet(this, _StructuredSelector_selector, "f").nodes[0].value ?? null : null;
const nodes = __classPrivateFieldGet(this, _StructuredSelector_selector, "f").nodes.slice();
const nodes = [...__classPrivateFieldGet(this, _StructuredSelector_selector, "f").nodes];
if (0 < depth && this.headCombinator) {

@@ -101,3 +109,3 @@ // eslint-disable-next-line import/no-named-as-default-member

}
nodes.forEach(node => {
for (const node of nodes) {
switch (node.type) {

@@ -124,3 +132,3 @@ case 'combinator': {

}
});
}
}

@@ -520,3 +528,3 @@ get selector() {

el) {
return Array.from(el.attributes).some(attrOfEl => {
return [...el.attributes].some(attrOfEl => {
if (attr.attribute !== attrOfEl.localName) {

@@ -641,4 +649,4 @@ return false;

matched: matched.length > 0,
nodes: matched.map(m => m.nodes).flat(),
has: matched.map(m => m.has).flat(),
nodes: matched.flatMap(m => m.nodes),
has: matched.flatMap(m => m.has),
};

@@ -652,5 +660,3 @@ }

case '~': {
const has = getSiblings(el)
.map(sib => ruleset.match(sib, el).filter((m) => m.matched))
.flat();
const has = getSiblings(el).flatMap(sib => ruleset.match(sib, el).filter((m) => m.matched));
if (has.length > 0) {

@@ -670,5 +676,3 @@ return {

default: {
const has = getDescendants(el)
.map(sib => ruleset.match(sib, el).filter((m) => m.matched))
.flat();
const has = getDescendants(el).flatMap(sib => ruleset.match(sib, el).filter((m) => m.matched));
if (has.length > 0) {

@@ -696,4 +700,4 @@ return {

matched: matched.length > 0,
nodes: matched.map(m => m.nodes).flat(),
has: matched.map(m => m.has).flat(),
nodes: matched.flatMap(m => m.nodes),
has: matched.flatMap(m => m.has),
};

@@ -760,2 +764,3 @@ }

}
/* eslint-disable unicorn/no-useless-switch-case */
case ':dir':

@@ -794,2 +799,3 @@ case ':lang':

}
/* eslint-enable unicorn/no-useless-switch-case */
}

@@ -807,8 +813,3 @@ }

el, includeSelf = false) {
return [
...Array.from(el.children)
.map(child => getDescendants(child, true))
.flat(),
...(includeSelf ? [el] : []),
];
return [...[...el.children].flatMap(child => getDescendants(child, true)), ...(includeSelf ? [el] : [])];
}

@@ -818,3 +819,3 @@ function getSiblings(

el) {
return Array.from(el.parentElement?.children ?? []);
return [...(el.parentElement?.children ?? [])];
}

@@ -824,3 +825,3 @@ function getSpecificity(

results) {
let specificity = undefined;
let specificity;
for (const result of results) {

@@ -827,0 +828,0 @@ if (specificity) {

{
"name": "@markuplint/selector",
"version": "4.0.0-alpha.3",
"version": "4.0.0-dev.28+0131de5e",
"description": "Extended W3C Selectors matcher",

@@ -28,14 +28,13 @@ "repository": "git@github.com:markuplint/markuplint.git",

"dependencies": {
"@markuplint/ml-spec": "4.0.0-alpha.3",
"@types/debug": "^4.1.9",
"@markuplint/ml-spec": "4.0.0-dev.28+0131de5e",
"@types/debug": "^4.1.10",
"debug": "^4.3.4",
"postcss-selector-parser": "^6.0.13",
"tslib": "^2.6.2",
"type-fest": "^4.3.1"
"type-fest": "^4.5.0"
},
"devDependencies": {
"@types/jsdom": "21.1.3",
"@types/jsdom": "21.1.4",
"jsdom": "22.1.0"
},
"gitHead": "380836f7adc1ff7e8eaf9d869e68d29eee8f3b7e"
"gitHead": "0131de5ea9dd6d3fd5472d7b414b66644c758881"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc