Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "parsel-js", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "A tiny, permissive CSS selector parser", | ||
"main": "parsel.js", | ||
"scripts": { | ||
"test": "open test.html" | ||
"test": "open test.html", | ||
"build": "node build.js" | ||
}, | ||
@@ -9,0 +10,0 @@ "repository": { |
@@ -0,0 +0,0 @@ /** |
@@ -115,2 +115,6 @@ const TOKENS = { | ||
export function tokenize (selector) { | ||
if (!selector) { | ||
return null; | ||
} | ||
selector = selector.trim(); // prevent leading/trailing whitespace be interpreted as combinators | ||
@@ -132,3 +136,3 @@ | ||
selector = selector.substring(0, start) + "(" + "¶".repeat(str.length - 2) + ")" + selector.substring(start + str.length); | ||
offset += start + str.length; | ||
offset = start + str.length; | ||
} | ||
@@ -168,3 +172,3 @@ | ||
if (list && tokens.find(t => t.type === "comma")) { | ||
let list = [], temp = []; | ||
let selectors = [], temp = []; | ||
@@ -177,3 +181,3 @@ for (let i=0; i<tokens.length; i++) { | ||
list.push(nestTokens(temp, {list: false})); | ||
selectors.push(nestTokens(temp, {list: false})); | ||
temp.length = 0; | ||
@@ -190,6 +194,6 @@ } | ||
else { | ||
list.push(nestTokens(temp, {list: false})); | ||
selectors.push(nestTokens(temp, {list: false})); | ||
} | ||
return { type: "list", list }; | ||
return { type: "list", list: selectors }; | ||
} | ||
@@ -220,3 +224,3 @@ | ||
type: "compound", | ||
list: tokens | ||
list: [...tokens] // clone to avoid pointers messing up the AST | ||
}; | ||
@@ -226,17 +230,17 @@ } | ||
// Traverse an AST (or part thereof), in depth-first order | ||
export function walk(node, callback, {subtree = false} = {}) { | ||
export function walk(node, callback, o, parent) { | ||
if (node.type === "complex") { | ||
walk(node.left, callback); | ||
walk(node.right, callback); | ||
walk(node.left, callback, o, node); | ||
walk(node.right, callback, o, node); | ||
} | ||
else if (node.type === "compound") { | ||
for (let n of node.list) { | ||
walk(n, callback); | ||
walk(n, callback, o, node); | ||
} | ||
} | ||
else if (node.subtree && subtree) { | ||
walk(node.subtree, callback); | ||
else if (node.subtree && o && o.subtree) { | ||
walk(node.subtree, callback, o, node); | ||
} | ||
callback(node); | ||
callback(node, parent); | ||
} | ||
@@ -252,2 +256,7 @@ | ||
let tokens = tokenize(selector); | ||
if (!tokens) { | ||
return null; | ||
} | ||
let ast = nestTokens(tokens, {list}); | ||
@@ -269,3 +278,3 @@ | ||
return specificity[0] * base ** 2 + specificity[1] * base + specificity[0]; | ||
return specificity[0] * base ** 2 + specificity[1] * base + specificity[2]; | ||
} | ||
@@ -293,2 +302,6 @@ | ||
if (!ast) { | ||
return null; | ||
} | ||
if (ast.type === "list") { | ||
@@ -320,3 +333,3 @@ // Return max specificity | ||
else if (node.type === "pseudo-class" && node.name !== "where") { | ||
if (RECURSIVE_PSEUDO_CLASSES.has(node.name)) { | ||
if (RECURSIVE_PSEUDO_CLASSES.has(node.name) && node.subtree) { | ||
// Max of argument list | ||
@@ -323,0 +336,0 @@ let sub = specificity(node.subtree); |
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
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
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
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
55596
12
1134
0
5
1