@vltpkg/dss-parser 1.0.0-rc.18 → 1.0.0-rc.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +23 -19
- package/dist/index.d.ts +0 -16
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -93
- package/dist/index.js.map +0 -1
- package/dist/types.d.ts +0 -26
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -119
- package/dist/types.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vltpkg/dss-parser",
|
|
3
3
|
"description": "The Dependency Selector Syntax (DSS) parser",
|
|
4
|
-
"version": "1.0.0-rc.
|
|
4
|
+
"version": "1.0.0-rc.22",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/vltpkg/vltpkg.git",
|
|
8
8
|
"directory": "src/dss-parser"
|
|
9
9
|
},
|
|
10
|
-
"author":
|
|
10
|
+
"author": {
|
|
11
|
+
"name": "vlt technology inc.",
|
|
12
|
+
"email": "support@vlt.sh"
|
|
13
|
+
},
|
|
11
14
|
"dependencies": {
|
|
12
|
-
"
|
|
13
|
-
"
|
|
15
|
+
"@vltpkg/error-cause": "1.0.0-rc.22",
|
|
16
|
+
"postcss-selector-parser": "^7.1.1"
|
|
14
17
|
},
|
|
15
18
|
"devDependencies": {
|
|
16
19
|
"@eslint/js": "^9.39.1",
|
|
@@ -24,33 +27,34 @@
|
|
|
24
27
|
},
|
|
25
28
|
"license": "BSD-2-Clause-Patent",
|
|
26
29
|
"engines": {
|
|
27
|
-
"node": ">=22.
|
|
30
|
+
"node": ">=22.22.0"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"format": "prettier --write . --log-level warn --ignore-path ../../.prettierignore --cache",
|
|
34
|
+
"format:check": "prettier --check . --ignore-path ../../.prettierignore --cache",
|
|
35
|
+
"lint": "eslint . --fix",
|
|
36
|
+
"lint:check": "eslint .",
|
|
37
|
+
"prepack": "tsc -p tsconfig.publish.json && ../../scripts/update-dist-exports.ts",
|
|
38
|
+
"snap": "tap",
|
|
39
|
+
"test": "tap",
|
|
40
|
+
"posttest": "tsc --noEmit",
|
|
41
|
+
"typecheck": "tsc --noEmit"
|
|
28
42
|
},
|
|
29
43
|
"tap": {
|
|
30
44
|
"extends": "../../tap-config.yaml"
|
|
31
45
|
},
|
|
32
46
|
"prettier": "../../.prettierrc.js",
|
|
33
|
-
"module": "./
|
|
47
|
+
"module": "./src/index.ts",
|
|
34
48
|
"type": "module",
|
|
35
49
|
"exports": {
|
|
36
50
|
"./package.json": "./package.json",
|
|
37
51
|
".": {
|
|
38
52
|
"import": {
|
|
39
|
-
"default": "./
|
|
53
|
+
"default": "./src/index.ts"
|
|
40
54
|
}
|
|
41
55
|
}
|
|
42
56
|
},
|
|
43
57
|
"files": [
|
|
44
58
|
"dist"
|
|
45
|
-
]
|
|
46
|
-
|
|
47
|
-
"format": "prettier --write . --log-level warn --ignore-path ../../.prettierignore --cache",
|
|
48
|
-
"format:check": "prettier --check . --ignore-path ../../.prettierignore --cache",
|
|
49
|
-
"lint": "eslint . --fix",
|
|
50
|
-
"lint:check": "eslint .",
|
|
51
|
-
"snap": "tap",
|
|
52
|
-
"test": "tap",
|
|
53
|
-
"posttest": "tsc --noEmit",
|
|
54
|
-
"typecheck": "tsc --noEmit"
|
|
55
|
-
}
|
|
56
|
-
}
|
|
59
|
+
]
|
|
60
|
+
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { Root } from 'postcss-selector-parser';
|
|
2
|
-
export * from './types.ts';
|
|
3
|
-
/**
|
|
4
|
-
* Escapes forward slashes in specific patterns matching @scoped/name paths
|
|
5
|
-
* This will allow usage of unescaped forward slashes necessary for scoped
|
|
6
|
-
* package names in the id selector.
|
|
7
|
-
*/
|
|
8
|
-
export declare const escapeScopedNamesSlashes: (query: string) => string;
|
|
9
|
-
export declare const escapeDots: (query: string) => string;
|
|
10
|
-
export declare const unescapeDots: (query: string) => string;
|
|
11
|
-
/**
|
|
12
|
-
* Parses a CSS selector string into an AST
|
|
13
|
-
* Handles escaping of forward slashes in specific patterns
|
|
14
|
-
*/
|
|
15
|
-
export declare const parse: (query: string) => Root;
|
|
16
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAU,IAAI,EAAE,MAAM,yBAAyB,CAAA;AAS3D,cAAc,YAAY,CAAA;AAE1B;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,UAAW,MAAM,KAAG,MAItD,CAAA;AAEH,eAAO,MAAM,UAAU,UAAW,MAAM,KAAG,MACb,CAAA;AAE9B,eAAO,MAAM,YAAY,UAAW,MAAM,KAAG,MACf,CAAA;AAgB9B;;;GAGG;AACH,eAAO,MAAM,KAAK,UAAW,MAAM,KAAG,IA0ErC,CAAA"}
|
package/dist/index.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import postcssSelectorParser from 'postcss-selector-parser';
|
|
2
|
-
import { asSelectorNode, isCombinatorNode, isPseudoNode, isTagNode, } from "./types.js";
|
|
3
|
-
export * from "./types.js";
|
|
4
|
-
/**
|
|
5
|
-
* Escapes forward slashes in specific patterns matching @scoped/name paths
|
|
6
|
-
* This will allow usage of unescaped forward slashes necessary for scoped
|
|
7
|
-
* package names in the id selector.
|
|
8
|
-
*/
|
|
9
|
-
export const escapeScopedNamesSlashes = (query) => query.replace(/(#@(\w|-|\.)+)\//gm, (_, scope) => `${scope}\\/`);
|
|
10
|
-
export const escapeDots = (query) => query.replaceAll('.', '\\.');
|
|
11
|
-
export const unescapeDots = (query) => query.replaceAll('\\.', '.');
|
|
12
|
-
const pseudoCleanUpNeeded = new Set([
|
|
13
|
-
':published',
|
|
14
|
-
':score',
|
|
15
|
-
':malware',
|
|
16
|
-
':severity',
|
|
17
|
-
':sev',
|
|
18
|
-
':squat',
|
|
19
|
-
':semver',
|
|
20
|
-
':v',
|
|
21
|
-
]);
|
|
22
|
-
const hasParamsToEscape = (node) => pseudoCleanUpNeeded.has(node.value);
|
|
23
|
-
/**
|
|
24
|
-
* Parses a CSS selector string into an AST
|
|
25
|
-
* Handles escaping of forward slashes in specific patterns
|
|
26
|
-
*/
|
|
27
|
-
export const parse = (query) => {
|
|
28
|
-
const escapedQuery = escapeDots(escapeScopedNamesSlashes(query));
|
|
29
|
-
const transformAst = (root) => {
|
|
30
|
-
root.walk((node) => {
|
|
31
|
-
// clean up the escaped dots
|
|
32
|
-
if (node.value && typeof node.value === 'string') {
|
|
33
|
-
node.value = unescapeDots(node.value);
|
|
34
|
-
}
|
|
35
|
-
if (isPseudoNode(node) && hasParamsToEscape(node)) {
|
|
36
|
-
// these are pseudo nodes that should only take strings as
|
|
37
|
-
// parameters, so in this preparse step we clean up anything
|
|
38
|
-
// that was recognized as a postcss node and transform that
|
|
39
|
-
// into something that can be most likely parsed as a string
|
|
40
|
-
for (const n of node.nodes) {
|
|
41
|
-
// the parameters have a selector node that wraps them up
|
|
42
|
-
const selector = asSelectorNode(n);
|
|
43
|
-
selector.nodes.forEach((currentNode, index, arr) => {
|
|
44
|
-
// get the next node, we'll update it later
|
|
45
|
-
const nextNode = arr[index + 1];
|
|
46
|
-
// if the current node is a combinator node, we'll need to
|
|
47
|
-
// escape it, we do so by removing the node entirely and
|
|
48
|
-
// updating the contents of the next node with its value
|
|
49
|
-
if (isCombinatorNode(currentNode) &&
|
|
50
|
-
isTagNode(nextNode)) {
|
|
51
|
-
nextNode.value = `${currentNode.spaces.before}${currentNode.value}${currentNode.spaces.after}${nextNode.value}`;
|
|
52
|
-
// make sure to also update the source position
|
|
53
|
-
// references, those are used by the syntax highlighter
|
|
54
|
-
if (nextNode.source?.start?.line &&
|
|
55
|
-
currentNode.source?.start?.line) {
|
|
56
|
-
nextNode.source.start.line =
|
|
57
|
-
currentNode.source.start.line;
|
|
58
|
-
}
|
|
59
|
-
if (nextNode.source?.start?.column &&
|
|
60
|
-
currentNode.source?.start?.column) {
|
|
61
|
-
nextNode.source.start.column =
|
|
62
|
-
currentNode.source.start.column;
|
|
63
|
-
}
|
|
64
|
-
// removes the current node from the selector node
|
|
65
|
-
arr.splice(index, 1);
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
// after removing combinator nodes, if we end up with multiple
|
|
69
|
-
// tags in the selector node, we need to smush them together
|
|
70
|
-
selector.nodes.reduce((acc, currentNode) => {
|
|
71
|
-
if (currentNode === acc)
|
|
72
|
-
return acc;
|
|
73
|
-
acc.value = `${acc.value}${currentNode.spaces.before}${currentNode.value}${currentNode.spaces.after}`;
|
|
74
|
-
// make sure to also update the source position refs
|
|
75
|
-
if (currentNode.source?.end?.line &&
|
|
76
|
-
acc.source?.end?.line) {
|
|
77
|
-
acc.source.end.line = currentNode.source.end.line;
|
|
78
|
-
}
|
|
79
|
-
if (currentNode.source?.end?.column &&
|
|
80
|
-
acc.source?.end?.column) {
|
|
81
|
-
acc.source.end.column = currentNode.source.end.column;
|
|
82
|
-
}
|
|
83
|
-
return acc;
|
|
84
|
-
}, selector.first);
|
|
85
|
-
// the selector wrapper node should have a single node
|
|
86
|
-
selector.nodes.length = 1;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
};
|
|
91
|
-
return postcssSelectorParser(transformAst).astSync(escapedQuery);
|
|
92
|
-
};
|
|
93
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,MAAM,yBAAyB,CAAA;AAE3D,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,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C,CAAA","sourcesContent":["import postcssSelectorParser from 'postcss-selector-parser'\nimport type { Pseudo, Root } from 'postcss-selector-parser'\nimport {\n asSelectorNode,\n isCombinatorNode,\n isPseudoNode,\n isTagNode,\n} from './types.ts'\nimport type { PostcssNode } from './types.ts'\n\nexport * from './types.ts'\n\n/**\n * Escapes forward slashes in specific patterns matching @scoped/name paths\n * This will allow usage of unescaped forward slashes necessary for scoped\n * package names in the id selector.\n */\nexport const escapeScopedNamesSlashes = (query: string): string =>\n query.replace(\n /(#@(\\w|-|\\.)+)\\//gm,\n (_, scope: string) => `${scope}\\\\/`,\n )\n\nexport const escapeDots = (query: string): string =>\n query.replaceAll('.', '\\\\.')\n\nexport const unescapeDots = (query: string): string =>\n query.replaceAll('\\\\.', '.')\n\nconst pseudoCleanUpNeeded = new Set([\n ':published',\n ':score',\n ':malware',\n ':severity',\n ':sev',\n ':squat',\n ':semver',\n ':v',\n])\n\nconst hasParamsToEscape = (node: Pseudo) =>\n pseudoCleanUpNeeded.has(node.value)\n\n/**\n * Parses a CSS selector string into an AST\n * Handles escaping of forward slashes in specific patterns\n */\nexport const parse = (query: string): Root => {\n const escapedQuery = escapeDots(escapeScopedNamesSlashes(query))\n const transformAst = (root: Root) => {\n root.walk((node: PostcssNode) => {\n // clean up the escaped dots\n if (node.value && typeof node.value === 'string') {\n node.value = unescapeDots(node.value)\n }\n if (isPseudoNode(node) && hasParamsToEscape(node)) {\n // these are pseudo nodes that should only take strings as\n // parameters, so in this preparse step we clean up anything\n // that was recognized as a postcss node and transform that\n // into something that can be most likely parsed as a string\n for (const n of node.nodes) {\n // the parameters have a selector node that wraps them up\n const selector = asSelectorNode(n)\n selector.nodes.forEach((currentNode, index, arr) => {\n // get the next node, we'll update it later\n const nextNode = arr[index + 1]\n // if the current node is a combinator node, we'll need to\n // escape it, we do so by removing the node entirely and\n // updating the contents of the next node with its value\n if (\n isCombinatorNode(currentNode) &&\n isTagNode(nextNode)\n ) {\n nextNode.value = `${currentNode.spaces.before}${currentNode.value}${currentNode.spaces.after}${nextNode.value}`\n // make sure to also update the source position\n // references, those are used by the syntax highlighter\n if (\n nextNode.source?.start?.line &&\n currentNode.source?.start?.line\n ) {\n nextNode.source.start.line =\n currentNode.source.start.line\n }\n if (\n nextNode.source?.start?.column &&\n currentNode.source?.start?.column\n ) {\n nextNode.source.start.column =\n currentNode.source.start.column\n }\n // removes the current node from the selector node\n arr.splice(index, 1)\n }\n })\n // after removing combinator nodes, if we end up with multiple\n // tags in the selector node, we need to smush them together\n selector.nodes.reduce((acc, currentNode) => {\n if (currentNode === acc) return acc\n acc.value = `${acc.value}${currentNode.spaces.before}${currentNode.value}${currentNode.spaces.after}`\n // make sure to also update the source position refs\n if (\n currentNode.source?.end?.line &&\n acc.source?.end?.line\n ) {\n acc.source.end.line = currentNode.source.end.line\n }\n if (\n currentNode.source?.end?.column &&\n acc.source?.end?.column\n ) {\n acc.source.end.column = currentNode.source.end.column\n }\n return acc\n }, selector.first)\n // the selector wrapper node should have a single node\n selector.nodes.length = 1\n }\n }\n })\n }\n return postcssSelectorParser(transformAst).astSync(escapedQuery)\n}\n"]}
|
package/dist/types.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { Tag, String, Selector, Root, Pseudo, Nesting, Identifier, Comment, Combinator, ClassName, Attribute, Universal, tag, id, combinator, string, attribute, pseudo } from 'postcss-selector-parser';
|
|
2
|
-
export type PostcssNode = Tag | String | Selector | Root | Pseudo | Nesting | Identifier | Comment | Combinator | ClassName | Attribute | Universal;
|
|
3
|
-
export type PostCSSLeaf = ReturnType<typeof tag> | ReturnType<typeof id> | ReturnType<typeof attribute> | ReturnType<typeof combinator> | ReturnType<typeof pseudo> | ReturnType<typeof string>;
|
|
4
|
-
export type PostcssNodeWithChildren = Selector | Root | Pseudo;
|
|
5
|
-
export type ParsedSelectorToken = PostcssNode & {
|
|
6
|
-
token: string;
|
|
7
|
-
};
|
|
8
|
-
export declare const isPostcssNodeWithChildren: (node: any) => node is PostcssNodeWithChildren;
|
|
9
|
-
export declare const asPostcssNodeWithChildren: (node?: PostcssNode) => PostcssNodeWithChildren;
|
|
10
|
-
export declare const isAttributeNode: (node: unknown) => node is Attribute;
|
|
11
|
-
export declare const asAttributeNode: (node?: PostcssNode) => Attribute;
|
|
12
|
-
export declare const isCombinatorNode: (node: unknown) => node is Combinator;
|
|
13
|
-
export declare const asCombinatorNode: (node?: PostcssNode) => Combinator;
|
|
14
|
-
export declare const isIdentifierNode: (node: any) => node is Identifier;
|
|
15
|
-
export declare const asIdentifierNode: (node?: PostcssNode) => Identifier;
|
|
16
|
-
export declare const isSelectorNode: (node: any) => node is Selector;
|
|
17
|
-
export declare const asSelectorNode: (node?: PostcssNode) => Selector;
|
|
18
|
-
export declare const isPseudoNode: (node: unknown) => node is Pseudo;
|
|
19
|
-
export declare const asPseudoNode: (node?: PostcssNode) => Pseudo;
|
|
20
|
-
export declare const isTagNode: (node: unknown) => node is Tag;
|
|
21
|
-
export declare const asTagNode: (node?: PostcssNode) => Tag;
|
|
22
|
-
export declare const isStringNode: (node: unknown) => node is String;
|
|
23
|
-
export declare const asStringNode: (node?: PostcssNode) => String;
|
|
24
|
-
export declare const isCommentNode: (node: unknown) => node is Comment;
|
|
25
|
-
export declare const asCommentNode: (node?: PostcssNode) => Comment;
|
|
26
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,GAAG,EACH,MAAM,EACN,QAAQ,EACR,IAAI,EACJ,MAAM,EACN,OAAO,EACP,UAAU,EACV,OAAO,EACP,UAAU,EACV,SAAS,EACT,SAAS,EACT,SAAS,EACT,GAAG,EACH,EAAE,EACF,UAAU,EACV,MAAM,EACN,SAAS,EACT,MAAM,EACP,MAAM,yBAAyB,CAAA;AAEhC,MAAM,MAAM,WAAW,G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AEvD,eAAO,MAAM,YAAY,UAAW,WAAW,KAAG,MAYjD,CAAA;AAED,eAAO,MAAM,SAAS,SAAU,OAAO,KAAG,IAAI,IAAI,GACE,CAAA;AAEpD,eAAO,MAAM,SAAS,UAAW,WAAW,KAAG,GAa9C,CAAA;AAED,eAAO,MAAM,YAAY,SAAU,OAAO,KAAG,IAAI,IAAI,MACE,CAAA;AAEvD,eAAO,MAAM,YAAY,UAAW,WAAW,KAAG,MAajD,CAAA;AAED,eAAO,MAAM,aAAa,SAAU,OAAO,KAAG,IAAI,IAAI,OACE,CAAA;AAExD,eAAO,MAAM,aAAa,UAAW,WAAW,KAAG,OAalD,CAAA"}
|
package/dist/types.js
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { error } from '@vltpkg/error-cause';
|
|
2
|
-
export const isPostcssNodeWithChildren = (node) => 'type' in node && 'nodes' in node;
|
|
3
|
-
export const asPostcssNodeWithChildren = (node) => {
|
|
4
|
-
if (!node) {
|
|
5
|
-
throw error('Expected a query node');
|
|
6
|
-
}
|
|
7
|
-
if (!isPostcssNodeWithChildren(node)) {
|
|
8
|
-
throw error('Not a query selector node with children', {
|
|
9
|
-
found: node,
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
return node;
|
|
13
|
-
};
|
|
14
|
-
const isObj = (o) => !!o && typeof o === 'object';
|
|
15
|
-
export const isAttributeNode = (node) => isObj(node) && !!node.attribute && node.type === 'attribute';
|
|
16
|
-
export const asAttributeNode = (node) => {
|
|
17
|
-
if (!node) {
|
|
18
|
-
throw error('Expected a query node');
|
|
19
|
-
}
|
|
20
|
-
if (!isAttributeNode(node)) {
|
|
21
|
-
throw error('Mismatching query node', {
|
|
22
|
-
wanted: 'attribute',
|
|
23
|
-
found: node.type,
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
return node;
|
|
27
|
-
};
|
|
28
|
-
export const isCombinatorNode = (node) => isObj(node) && !!node.value && node.type === 'combinator';
|
|
29
|
-
export const asCombinatorNode = (node) => {
|
|
30
|
-
if (!node) {
|
|
31
|
-
throw error('Expected a query node');
|
|
32
|
-
}
|
|
33
|
-
if (!isCombinatorNode(node)) {
|
|
34
|
-
throw error('Mismatching query node', {
|
|
35
|
-
wanted: 'combinator',
|
|
36
|
-
found: node.type,
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
return node;
|
|
40
|
-
};
|
|
41
|
-
export const isIdentifierNode = (node) => isObj(node) && !!node.value && node.type === 'id';
|
|
42
|
-
export const asIdentifierNode = (node) => {
|
|
43
|
-
if (!node) {
|
|
44
|
-
throw error('Expected a query node');
|
|
45
|
-
}
|
|
46
|
-
if (!isIdentifierNode(node)) {
|
|
47
|
-
throw error('Mismatching query node', {
|
|
48
|
-
wanted: 'id',
|
|
49
|
-
found: node.type,
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
return node;
|
|
53
|
-
};
|
|
54
|
-
export const isSelectorNode = (node) => isPostcssNodeWithChildren(node) && node.type === 'selector';
|
|
55
|
-
export const asSelectorNode = (node) => {
|
|
56
|
-
if (!node) {
|
|
57
|
-
throw error('Expected a query node');
|
|
58
|
-
}
|
|
59
|
-
if (!isSelectorNode(node)) {
|
|
60
|
-
throw error('Mismatching query node', {
|
|
61
|
-
wanted: 'selector',
|
|
62
|
-
found: node.type,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
return node;
|
|
66
|
-
};
|
|
67
|
-
export const isPseudoNode = (node) => isObj(node) && !!node.value && node.type === 'pseudo';
|
|
68
|
-
export const asPseudoNode = (node) => {
|
|
69
|
-
if (!node) {
|
|
70
|
-
throw error('Expected a query node');
|
|
71
|
-
}
|
|
72
|
-
if (!isPseudoNode(node)) {
|
|
73
|
-
throw error('Mismatching query node', {
|
|
74
|
-
wanted: 'pseudo',
|
|
75
|
-
found: node.type,
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
return node;
|
|
79
|
-
};
|
|
80
|
-
export const isTagNode = (node) => isObj(node) && !!node.value && node.type === 'tag';
|
|
81
|
-
export const asTagNode = (node) => {
|
|
82
|
-
if (!node) {
|
|
83
|
-
throw error('Expected a query node');
|
|
84
|
-
}
|
|
85
|
-
if (!isTagNode(node)) {
|
|
86
|
-
throw error('Mismatching query node', {
|
|
87
|
-
wanted: 'tag',
|
|
88
|
-
found: node.type,
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
return node;
|
|
92
|
-
};
|
|
93
|
-
export const isStringNode = (node) => isObj(node) && !!node.value && node.type === 'string';
|
|
94
|
-
export const asStringNode = (node) => {
|
|
95
|
-
if (!node) {
|
|
96
|
-
throw error('Expected a query node');
|
|
97
|
-
}
|
|
98
|
-
if (!isStringNode(node)) {
|
|
99
|
-
throw error('Mismatching query node', {
|
|
100
|
-
wanted: 'string',
|
|
101
|
-
found: node.type,
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
return node;
|
|
105
|
-
};
|
|
106
|
-
export const isCommentNode = (node) => isObj(node) && !!node.value && node.type === 'comment';
|
|
107
|
-
export const asCommentNode = (node) => {
|
|
108
|
-
if (!node) {
|
|
109
|
-
throw error('Expected a query node');
|
|
110
|
-
}
|
|
111
|
-
if (!isCommentNode(node)) {
|
|
112
|
-
throw error('Mismatching query node', {
|
|
113
|
-
wanted: 'comment',
|
|
114
|
-
found: node.type,
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
return node;
|
|
118
|
-
};
|
|
119
|
-
//# sourceMappingURL=types.js.map
|
package/dist/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAkD3C,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,IAAS,EACwB,EAAE,CACnC,MAAM,IAAI,IAAI,IAAI,OAAO,IAAI,IAAI,CAAA;AAEnC,MAAM,CAAC,MAAM,yBAAy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AAM,YAAY,GAAG,CAAC,IAAa,EAAkB,EAAE,CAC5D,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAA;AAEvD,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,IAAkB,EAAU,EAAE;IACzD,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,KAAK,CAAC,uBAAuB,CAAC,CAAA;IACtC,CAAC;IAED,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,MAAM,KAAK,CAAC,wBAAwB,EAAE;YACpC,MAAM,EAAE,QAAQ;YAChB,KAAK,EAAE,IAAI,CAAC,IAAI;SACjB,CAAC,CAAA;IACJ,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,IAAa,EAAmB,EAAE,CAC9D,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,CAAA;AAExD,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,IAAkB,EAAW,EAAE;IAC3D,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,KAAK,CAAC,uBAAuB,CAAC,CAAA;IACtC,CAAC;IAED,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC;QACzB,MAAM,KAAK,CAAC,wBAAwB,EAAE;YACpC,MAAM,EAAE,SAAS;YACjB,KAAK,EAAE,IAAI,CAAC,IAAI;SACjB,CAAC,CAAA;IACJ,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC,CAAA","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport type {\n Tag,\n String,\n Selector,\n Root,\n Pseudo,\n Nesting,\n Identifier,\n Comment,\n Combinator,\n ClassName,\n Attribute,\n Universal,\n tag,\n id,\n combinator,\n string,\n attribute,\n pseudo,\n} from 'postcss-selector-parser'\n\nexport type PostcssNode =\n | Tag\n | String\n | Selector\n | Root\n | Pseudo\n | Nesting\n | Identifier\n | Comment\n | Combinator\n | ClassName\n | Attribute\n | Universal\n\nexport type PostCSSLeaf =\n | ReturnType<typeof tag>\n | ReturnType<typeof id>\n | ReturnType<typeof attribute>\n | ReturnType<typeof combinator>\n | ReturnType<typeof pseudo>\n | ReturnType<typeof string>\n\nexport type PostcssNodeWithChildren = Selector | Root | Pseudo\n\nexport type ParsedSelectorToken = PostcssNode & {\n token: string\n}\n\nexport const isPostcssNodeWithChildren = (\n node: any,\n): node is PostcssNodeWithChildren =>\n 'type' in node && 'nodes' in node\n\nexport const asPostcssNodeWithChildren = (\n node?: PostcssNode,\n): PostcssNodeWithChildren => {\n if (!node) {\n throw error('Expected a query node')\n }\n\n if (!isPostcssNodeWithChildren(node)) {\n throw error('Not a query selector node with children', {\n found: node,\n })\n }\n return node\n}\n\nconst isObj = (o: unknown): o is Record<string, unknown> =>\n !!o && typeof o === 'object'\n\nexport const isAttributeNode = (node: unknown): node is Attribute =>\n isObj(node) && !!node.attribute && node.type === 'attribute'\n\nexport const asAttributeNode = (node?: PostcssNode): Attribute => {\n if (!node) {\n throw error('Expected a query node')\n }\n\n if (!isAttributeNode(node)) {\n throw error('Mismatching query node', {\n wanted: 'attribute',\n found: node.type,\n })\n }\n return node\n}\n\nexport const isCombinatorNode = (node: unknown): node is Combinator =>\n isObj(node) && !!node.value && node.type === 'combinator'\n\nexport const asCombinatorNode = (node?: PostcssNode): Combinator => {\n if (!node) {\n throw error('Expected a query node')\n }\n\n if (!isCombinatorNode(node)) {\n throw error('Mismatching query node', {\n wanted: 'combinator',\n found: node.type,\n })\n }\n return node\n}\n\nexport const isIdentifierNode = (node: any): node is Identifier =>\n isObj(node) && !!node.value && node.type === 'id'\n\nexport const asIdentifierNode = (node?: PostcssNode): Identifier => {\n if (!node) {\n throw error('Expected a query node')\n }\n\n if (!isIdentifierNode(node)) {\n throw error('Mismatching query node', {\n wanted: 'id',\n found: node.type,\n })\n }\n return node\n}\n\nexport const isSelectorNode = (node: any): node is Selector =>\n isPostcssNodeWithChildren(node) && node.type === 'selector'\n\nexport const asSelectorNode = (node?: PostcssNode): Selector => {\n if (!node) {\n throw error('Expected a query node')\n }\n\n if (!isSelectorNode(node)) {\n throw error('Mismatching query node', {\n wanted: 'selector',\n found: node.type,\n })\n }\n return node\n}\n\nexport const isPseudoNode = (node: unknown): node is Pseudo =>\n isObj(node) && !!node.value && node.type === 'pseudo'\n\nexport const asPseudoNode = (node?: PostcssNode): Pseudo => {\n if (!node) {\n throw error('Expected a query node')\n }\n\n if (!isPseudoNode(node)) {\n throw error('Mismatching query node', {\n wanted: 'pseudo',\n found: node.type,\n })\n }\n return node\n}\n\nexport const isTagNode = (node: unknown): node is Tag =>\n isObj(node) && !!node.value && node.type === 'tag'\n\nexport const asTagNode = (node?: PostcssNode): Tag => {\n if (!node) {\n throw error('Expected a query node')\n }\n\n if (!isTagNode(node)) {\n throw error('Mismatching query node', {\n wanted: 'tag',\n found: node.type,\n })\n }\n\n return node\n}\n\nexport const isStringNode = (node: unknown): node is String =>\n isObj(node) && !!node.value && node.type === 'string'\n\nexport const asStringNode = (node?: PostcssNode): String => {\n if (!node) {\n throw error('Expected a query node')\n }\n\n if (!isStringNode(node)) {\n throw error('Mismatching query node', {\n wanted: 'string',\n found: node.type,\n })\n }\n\n return node\n}\n\nexport const isCommentNode = (node: unknown): node is Comment =>\n isObj(node) && !!node.value && node.type === 'comment'\n\nexport const asCommentNode = (node?: PostcssNode): Comment => {\n if (!node) {\n throw error('Expected a query node')\n }\n\n if (!isCommentNode(node)) {\n throw error('Mismatching query node', {\n wanted: 'comment',\n found: node.type,\n })\n }\n\n return node\n}\n"]}
|