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

parsel-js

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parsel-js - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

dist/cjs/parsel.js

21

package.json
{
"name": "parsel-js",
"version": "1.0.1",
"version": "1.0.2",
"description": "A tiny, permissive CSS selector parser",
"main": "parsel.js",
"main": "dist/cjs/parsel.min.js",
"module": "dist/parsel.min.js",
"exports": {
".": {
"import": "./dist/parsel.min.js",
"require": "./dist/cjs/parsel.min.js",
"browser": "./parsel.js",
"umd": "./dist/umd/parsel.min.js"
}
},
"scripts": {
"test": "open test.html",
"build": "node build.js"
"build": "rollup -c"
},

@@ -23,3 +32,7 @@ "repository": {

},
"homepage": "https://projects.verou.me/parsel"
"homepage": "https://projects.verou.me/parsel",
"devDependencies": {
"rollup": "^2.49.0",
"rollup-plugin-terser": "^7.0.2"
}
}

45

parsel.js

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

const TOKENS = {
attribute: /\[\s*(?:(?<namespace>\*|[-\w]*)\|)?(?<name>[-\w\u{0080}-\u{FFFF}]+)\s*(?:(?<operator>\W?=)\s*(?<value>.+?)\s*(?<i>i)?\s*)?\]/gu,
export const TOKENS = {
attribute: /\[\s*(?:(?<namespace>\*|[-\w]*)\|)?(?<name>[-\w\u{0080}-\u{FFFF}]+)\s*(?:(?<operator>\W?=)\s*(?<value>.+?)\s*(?<caseSensitive>[iIsS])?\s*)?\]/gu,
id: /#(?<name>(?:[-\w\u{0080}-\u{FFFF}]|\\.)+)/gu,

@@ -14,5 +14,11 @@ class: /\.(?<name>(?:[-\w\u{0080}-\u{FFFF}]|\\.)+)/gu,

const TOKENS_WITH_STRINGS = new Set([...TOKENS_WITH_PARENS, "attribute"]);
const TRIM_TOKENS = new Set(["combinator", "comma"]);
const RECURSIVE_PSEUDO_CLASSES = new Set(["not", "is", "where", "has", "matches", "-moz-any", "-webkit-any"]);
export const TRIM_TOKENS = new Set(["combinator", "comma"]);
export const RECURSIVE_PSEUDO_CLASSES = new Set(["not", "is", "where", "has", "matches", "-moz-any", "-webkit-any", "nth-child", "nth-last-child"]);
export const RECURSIVE_PSEUDO_CLASSES_ARGS = {
"nth-child": /(?<index>[\dn+-]+)\s+of\s+(?<subtree>.+)/
}
RECURSIVE_PSEUDO_CLASSES["nth-last-child"] = RECURSIVE_PSEUDO_CLASSES_ARGS["nth-child"];
const TOKENS_FOR_RESTORE = Object.assign({}, TOKENS);

@@ -204,6 +210,2 @@ TOKENS_FOR_RESTORE["pseudo-element"] = RegExp(TOKENS["pseudo-element"].source.replace("(?<argument>¶+)", "(?<argument>.+?)"), "gu")

if (left.length === 0 || right.length === 0) {
throw new Error(`Combinator ${token.content} used in selector ${left.length === 0? "start" : "end"}`);
}
return {

@@ -218,2 +220,6 @@ type: "complex",

if (tokens.length === 0) {
return null;
}
// If we're here, there are no combinators, so it's just a list

@@ -228,2 +234,6 @@ return tokens.length === 1? tokens[0] : {

export function walk(node, callback, o, parent) {
if (!node) {
return;
}
if (node.type === "complex") {

@@ -262,4 +272,19 @@ walk(node.left, callback, o, node);

walk(ast, node => {
if (node.type === "pseudo-class" && node.argument && RECURSIVE_PSEUDO_CLASSES.has(node.name)) {
node.subtree = parse(node.argument, {recursive: true, list: true});
if (node.type === "pseudo-class" && node.argument) {
if (RECURSIVE_PSEUDO_CLASSES.has(node.name)) {
let argument = node.argument;
const childArg = RECURSIVE_PSEUDO_CLASSES_ARGS[node.name];
if (childArg) {
const match = childArg.exec(argument);
if (!match) {
return;
}
Object.assign(node, match.groups);
argument = match.groups.subtree;
}
if (argument) {
node.subtree = parse(argument, {recursive: true, list: true});
}
}
}

@@ -266,0 +291,0 @@ });

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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