Comparing version 1.0.1 to 1.0.2
{ | ||
"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" | ||
} | ||
} |
@@ -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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
111590
21
2208
0
2
1