Comparing version 1.1.2 to 1.2.0
{ | ||
"name": "parsel-js", | ||
"version": "1.1.2", | ||
"version": "1.2.0", | ||
"description": "A tiny, permissive CSS selector parser", | ||
@@ -22,3 +22,4 @@ "type": "module", | ||
"build": "npx rollup -c", | ||
"prepublish": "npm run build" | ||
"prepublish": "npm run build", | ||
"release": "release-it" | ||
}, | ||
@@ -42,2 +43,3 @@ "repository": { | ||
"http-server": "^14.1.1", | ||
"release-it": "^17.10.0", | ||
"rollup": "^2.49.0", | ||
@@ -44,0 +46,0 @@ "rollup-plugin-terser": "^7.0.2", |
@@ -263,2 +263,10 @@ export const TOKENS: Record<string, RegExp> = { | ||
if (left.length === 0) { | ||
return { | ||
type: 'relative', | ||
combinator: token.content, | ||
right: nestTokens(right), | ||
}; | ||
} | ||
return { | ||
@@ -307,2 +315,5 @@ type: 'complex', | ||
break; | ||
case 'relative': | ||
yield* flatten(node.right, node); | ||
break; | ||
case 'compound': | ||
@@ -398,9 +409,25 @@ yield* node.list.map((token): [Token, Compound] => [token, node]); | ||
export function stringify(listOrNode: Token[] | AST): string { | ||
let tokens: Token[]; | ||
if (Array.isArray(listOrNode)) { | ||
tokens = listOrNode; | ||
} else { | ||
tokens = [...flatten(listOrNode)].map(([token]) => token); | ||
return listOrNode.map((token) => token.content).join(""); | ||
} | ||
return tokens.map(token => token.content).join('') | ||
switch (listOrNode.type) { | ||
case "list": | ||
return listOrNode.list.map(stringify).join(","); | ||
case "relative": | ||
return ( | ||
listOrNode.combinator + | ||
stringify(listOrNode.right) | ||
); | ||
case "complex": | ||
return ( | ||
stringify(listOrNode.left) + | ||
listOrNode.combinator + | ||
stringify(listOrNode.right) | ||
); | ||
case "compound": | ||
return listOrNode.list.map(stringify).join(""); | ||
default: | ||
return listOrNode.content; | ||
} | ||
} | ||
@@ -567,2 +594,8 @@ | ||
export interface Relative { | ||
type: 'relative'; | ||
combinator: string; | ||
right: AST; | ||
} | ||
export interface Compound { | ||
@@ -578,2 +611,2 @@ type: 'compound'; | ||
export type AST = Complex | Compound | List | Token; | ||
export type AST = Complex | Relative | Compound | List | Token; |
@@ -968,3 +968,83 @@ [ | ||
} | ||
}, | ||
{ | ||
"type": "tokenize", | ||
"input": ".container:has(~ .image)", | ||
"expected": [ | ||
{ | ||
"name": "container", | ||
"type": "class", | ||
"content": ".container", | ||
"pos": [ | ||
0, | ||
10 | ||
] | ||
}, | ||
{ | ||
"name": "has", | ||
"argument": "~ .image", | ||
"type": "pseudo-class", | ||
"content": ":has(~ .image)", | ||
"pos": [ | ||
10, | ||
24 | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "parse", | ||
"input": ".container:has(~ .image)", | ||
"expected": { | ||
"type": "compound", | ||
"list": [ | ||
{ | ||
"name": "container", | ||
"type": "class", | ||
"content": ".container", | ||
"pos": [ | ||
0, | ||
10 | ||
] | ||
}, | ||
{ | ||
"name": "has", | ||
"argument": "~ .image", | ||
"type": "pseudo-class", | ||
"content": ":has(~ .image)", | ||
"pos": [ | ||
10, | ||
24 | ||
], | ||
"subtree": { | ||
"type": "relative", | ||
"combinator": "~", | ||
"right": { | ||
"name": "image", | ||
"type": "class", | ||
"content": ".image", | ||
"pos": [ | ||
2, | ||
8 | ||
] | ||
} | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"type": "stringify", | ||
"input": ".container:has(~ .image)", | ||
"expected": ".container:has(~ .image)" | ||
}, | ||
{ | ||
"type": "specificity", | ||
"input": ".container:has(~ .image)", | ||
"expected": [ | ||
0, | ||
2, | ||
0 | ||
] | ||
} | ||
] |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
73686
7
17
2061
1