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

@tokey/css-selector-parser

Package Overview
Dependencies
Maintainers
3
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tokey/css-selector-parser - npm Package Compare versions

Comparing version 0.5.0 to 0.5.1

2

dist/ast-tools/compound.js

@@ -7,3 +7,3 @@ "use strict";

const context = createCompoundContext(options);
walk_1.walk(input, (node, _index, _nodes, parents) => {
(0, walk_1.walk)(input, (node, _index, _nodes, parents) => {
if (parents.length === 0 && node.type === `selector`) {

@@ -10,0 +10,0 @@ // first level: create top level selector

@@ -8,3 +8,3 @@ "use strict";

// ToDo: remove casting once immutable walk is supported
walk_1.walk(ast, (node) => {
(0, walk_1.walk)(ast, (node) => {
switch (node.type) {

@@ -11,0 +11,0 @@ case `type`:

@@ -19,7 +19,2 @@ import type { SelectorNode, SelectorList, ImmutableSelectorNode, ImmutableSelectorList } from "../ast-types";

export declare function walk<AST extends SelectorNode | SelectorList>(topNode: AST, visit: WalkVisitor<SelectorNode>, options?: WalkOptions): void;
export declare namespace walk {
var skipNested: 0;
var skipCurrentSelector: 1;
var stopAll: number;
}
export declare function walk<AST extends ImmutableSelectorNode | ImmutableSelectorList>(topNode: AST, visit: WalkVisitor<ImmutableSelectorNode>, options?: WalkOptions): void;

@@ -26,0 +21,0 @@ export declare namespace walk {

@@ -70,3 +70,3 @@ "use strict";

function ensureSelector(selectors, startToken) {
let lastSelector = core_1.last(selectors);
let lastSelector = (0, core_1.last)(selectors);
if (!lastSelector) {

@@ -85,3 +85,3 @@ lastSelector = createEmptySelector();

const firstNode = nodes[0];
const lastNode = core_1.last(nodes);
const lastNode = (0, core_1.last)(nodes);
// remove first space combinator and add to selector before

@@ -88,0 +88,0 @@ // (going between comment is not required for the start becuase they are taken care

@@ -69,3 +69,3 @@ "use strict";

// improve typing
const lastNode = core_1.last(this.ast);
const lastNode = (0, core_1.last)(this.ast);
if (lastNode) {

@@ -81,4 +81,4 @@ lastNode.after += token.value;

}
else if (core_1.isComment(type)) {
this.ast.push(helpers_1.createCommentAst(token));
else if ((0, core_1.isComment)(type)) {
this.ast.push((0, helpers_1.createCommentAst)(token));
return true;

@@ -85,0 +85,0 @@ }

@@ -9,3 +9,3 @@ "use strict";

function parseCssSelector(source, options = {}) {
return parseTokens(source, tokenizer_1.tokenizeSelector(source, options));
return parseTokens(source, (0, tokenizer_1.tokenizeSelector)(source, options));
}

@@ -19,3 +19,3 @@ exports.parseCssSelector = parseCssSelector;

let t;
const currentSelector = helpers_1.ensureSelector(selectors, token);
const currentSelector = (0, helpers_1.ensureSelector)(selectors, token);
const ast = currentSelector.nodes;

@@ -29,3 +29,3 @@ if (token.type === ".") {

start: token.start,
end: (_d = (_b = name === null || name === void 0 ? void 0 : name.end) !== null && _b !== void 0 ? _b : (_c = core_1.last(comments)) === null || _c === void 0 ? void 0 : _c.end) !== null && _d !== void 0 ? _d : token.end,
end: (_d = (_b = name === null || name === void 0 ? void 0 : name.end) !== null && _b !== void 0 ? _b : (_c = (0, core_1.last)(comments)) === null || _c === void 0 ? void 0 : _c.end) !== null && _d !== void 0 ? _d : token.end,
dotComments: comments,

@@ -40,3 +40,3 @@ });

const name = s.take("text");
const endToken = name || core_1.last(firstComments) || type;
const endToken = name || (0, core_1.last)(firstComments) || type;
ast.push({

@@ -53,3 +53,3 @@ type: "pseudo_class",

const name = s.take("text");
const endToken = name || core_1.last(secondComments) || type;
const endToken = name || (0, core_1.last)(secondComments) || type;
ast.push({

@@ -69,9 +69,9 @@ type: "pseudo_element",

}, [token], source);
const closed = ((_j = core_1.last(block)) === null || _j === void 0 ? void 0 : _j.type) === "]";
const closed = ((_j = (0, core_1.last)(block)) === null || _j === void 0 ? void 0 : _j.type) === "]";
if (closed) {
ast.push({
type: "attribute",
value: block.length > 2 ? core_1.getText(block, 1, block.length - 1, source) : "",
value: block.length > 2 ? (0, core_1.getText)(block, 1, block.length - 1, source) : "",
start: token.start,
end: (_l = (_k = core_1.last(block)) === null || _k === void 0 ? void 0 : _k.end) !== null && _l !== void 0 ? _l : token.end,
end: (_l = (_k = (0, core_1.last)(block)) === null || _k === void 0 ? void 0 : _k.end) !== null && _l !== void 0 ? _l : token.end,
});

@@ -82,10 +82,10 @@ }

type: "invalid",
value: core_1.getText(block, undefined, undefined, source),
value: (0, core_1.getText)(block, undefined, undefined, source),
start: token.start,
end: (_o = (_m = core_1.last(block)) === null || _m === void 0 ? void 0 : _m.end) !== null && _o !== void 0 ? _o : token.end,
end: (_o = (_m = (0, core_1.last)(block)) === null || _m === void 0 ? void 0 : _m.end) !== null && _o !== void 0 ? _o : token.end,
});
}
}
else if (helpers_1.isCombinatorToken(token)) {
let lastCombinatorAst = helpers_1.createCombinatorAst(token);
else if ((0, helpers_1.isCombinatorToken)(token)) {
let lastCombinatorAst = (0, helpers_1.createCombinatorAst)(token);
let lastAst = lastCombinatorAst;

@@ -114,3 +114,3 @@ // insert token as a combinator

while (next) {
if (helpers_1.isCombinatorToken(next)) {
if ((0, helpers_1.isCombinatorToken)(next)) {
if (next.type === `space`) {

@@ -124,3 +124,3 @@ // add space to the last ast node

// combine next combinator into previous (space)
const nextCombinator = helpers_1.createCombinatorAst(next);
const nextCombinator = (0, helpers_1.createCombinatorAst)(next);
lastCombinatorAst.combinator = nextCombinator.combinator;

@@ -160,3 +160,3 @@ lastCombinatorAst.before +=

// add combinator
lastCombinatorAst = helpers_1.createCombinatorAst(next);
lastCombinatorAst = (0, helpers_1.createCombinatorAst)(next);
lastAst = lastCombinatorAst;

@@ -167,3 +167,3 @@ ast.push(lastCombinatorAst);

// add invalid combinator
lastCombinatorAst = helpers_1.createCombinatorAst(next);
lastCombinatorAst = (0, helpers_1.createCombinatorAst)(next);
lastCombinatorAst.invalid = true;

@@ -174,4 +174,4 @@ lastAst = lastCombinatorAst;

}
else if (core_1.isComment(next.type)) {
lastAst = helpers_1.createCommentAst(next);
else if ((0, core_1.isComment)(next.type)) {
lastAst = (0, helpers_1.createCommentAst)(next);
ast.push(lastAst);

@@ -185,3 +185,3 @@ }

// put back any unrelated token
if (next && !helpers_1.isCombinatorToken(next)) {
if (next && !(0, helpers_1.isCombinatorToken)(next)) {
s.back();

@@ -222,3 +222,3 @@ }

const current = ast[i];
if (helpers_1.isNamespacedAst(current)) {
if ((0, helpers_1.isNamespacedAst)(current)) {
if (current.namespace) {

@@ -251,6 +251,6 @@ // already namespaced

const nextToken = s.peek(searchIndex);
if (core_1.isComment(nextToken.type)) {
if ((0, core_1.isComment)(nextToken.type)) {
potentialAfterComments.push(nextToken);
}
else if (helpers_1.isNamespacedToken(nextToken)) {
else if ((0, helpers_1.isNamespacedToken)(nextToken)) {
target = nextToken;

@@ -312,3 +312,3 @@ break;

else if (token.type === "(") {
const prev = core_1.last(ast);
const prev = (0, core_1.last)(ast);
const res = [];

@@ -321,3 +321,3 @@ // handle nth selector

// collect "An+B of" expression
const nthSelector = helpers_1.createEmptyNth();
const nthSelector = (0, helpers_1.createEmptyNth)();
nthSelector.start = s.peek().start;

@@ -336,5 +336,5 @@ res.push(nthSelector);

if (s.peek().type !== `)`) {
nthSelector.end = ((_r = core_1.last(nthSelector.nodes)) === null || _r === void 0 ? void 0 : _r.end) || nthSelector.start;
nthSelector.end = ((_r = (0, core_1.last)(nthSelector.nodes)) === null || _r === void 0 ? void 0 : _r.end) || nthSelector.start;
// add "of" selector
const newSelector = helpers_1.createEmptySelector();
const newSelector = (0, helpers_1.createEmptySelector)();
newSelector.start = nthSelector.end;

@@ -348,6 +348,6 @@ res.push(newSelector);

if (token.type === ")") {
const currentSelector = core_1.last(selectors);
const currentSelector = (0, core_1.last)(selectors);
if (currentSelector) {
currentSelector.end =
(_b = (_a = core_1.last(currentSelector.nodes)) === null || _a === void 0 ? void 0 : _a.end) !== null && _b !== void 0 ? _b : currentSelector.start;
(_b = (_a = (0, core_1.last)(currentSelector.nodes)) === null || _a === void 0 ? void 0 : _a.end) !== null && _b !== void 0 ? _b : currentSelector.start;
}

@@ -371,3 +371,3 @@ return false;

type: "invalid",
value: core_1.getText([token, ended], undefined, undefined, source),
value: (0, core_1.getText)([token, ended], undefined, undefined, source),
start: token.start,

@@ -379,4 +379,4 @@ end: (_s = ended === null || ended === void 0 ? void 0 : ended.end) !== null && _s !== void 0 ? _s : s.peekBack().end,

if (res.length) {
const lastSelector = core_1.last(res);
helpers_1.trimCombinators(lastSelector);
const lastSelector = (0, core_1.last)(res);
(0, helpers_1.trimCombinators)(lastSelector);
}

@@ -387,10 +387,10 @@ prev.nodes = res;

}
else if (core_1.isComment(token.type)) {
ast.push(helpers_1.createCommentAst(token));
else if ((0, core_1.isComment)(token.type)) {
ast.push((0, helpers_1.createCommentAst)(token));
}
else if (token.type === ",") {
const selector = core_1.last(selectors);
const selector = (0, core_1.last)(selectors);
selector.end = token.start;
helpers_1.trimCombinators(selector);
const newSelector = helpers_1.createEmptySelector();
(0, helpers_1.trimCombinators)(selector);
const newSelector = (0, helpers_1.createEmptySelector)();
if (s.done()) {

@@ -423,6 +423,6 @@ newSelector.start = token.end;

currentSelector.end =
(_u = (_t = core_1.last(currentSelector.nodes)) === null || _t === void 0 ? void 0 : _t.end) !== null && _u !== void 0 ? _u : currentSelector.start;
helpers_1.trimCombinators(currentSelector);
(_u = (_t = (0, core_1.last)(currentSelector.nodes)) === null || _t === void 0 ? void 0 : _t.end) !== null && _u !== void 0 ? _u : currentSelector.start;
(0, helpers_1.trimCombinators)(currentSelector);
}
}
//# sourceMappingURL=selector-parser.js.map

@@ -7,6 +7,6 @@ "use strict";

const parseLineComments = false; // why would that be a choice?
return core_1.tokenize(source, {
return (0, core_1.tokenize)(source, {
isDelimiter,
isStringDelimiter(char, previousChar) {
return previousChar !== `\\` && core_1.isStringDelimiter(char);
return previousChar !== `\\` && (0, core_1.isStringDelimiter)(char);
},

@@ -13,0 +13,0 @@ isWhitespace: core_1.isWhitespace,

@@ -5,6 +5,5 @@ /**

export declare type Immutable<T> = T extends Function ? T : T extends object ? ImmutableMap<T> : T;
declare type ImmutableMap<T> = {
export declare type ImmutableMap<T> = {
readonly [P in keyof T]: Immutable<T[P]>;
};
export {};
//# sourceMappingURL=types.d.ts.map
{
"name": "@tokey/css-selector-parser",
"description": "selector parser for css",
"version": "0.5.0",
"version": "0.5.1",
"main": "dist/index.js",

@@ -6,0 +6,0 @@ "types": "dist/index.d.ts",

@@ -10,5 +10,5 @@ /**

type ImmutableMap<T> = {
export type ImmutableMap<T> = {
readonly [P in keyof T]: Immutable<T[P]>;
};

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

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

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