@vltpkg/dss-parser 0.0.0-14
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/LICENSE +15 -0
- package/README.md +16 -0
- package/dist/esm/index.d.ts +16 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +93 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/types.d.ts +25 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +119 -0
- package/dist/esm/types.js.map +1 -0
- package/package.json +69 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Copyright (c) vlt technology, Inc.
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
|
+
|
|
5
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
7
|
+
Subject to the terms and conditions of this license, each copyright holder and contributor hereby grants to those receiving rights under this license a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except for failure to satisfy the conditions of this license) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer this software, where such license applies only to those patent claims, already acquired or hereafter acquired, licensable by such copyright holder or contributor that are necessarily infringed by:
|
|
8
|
+
|
|
9
|
+
(a) their Contribution(s) (the licensed copyrights of copyright holders and non-copyrightable additions of contributors, in source or binary form) alone; or
|
|
10
|
+
(b) combination of their Contribution(s) with the work of authorship to which such Contribution(s) was added by such copyright holder or contributor, if, at the time the Contribution is added, such addition causes such combination to be necessarily infringed. The patent license shall not apply to any other combinations which include the Contribution.
|
|
11
|
+
Except as expressly stated above, no rights or licenses from any copyright holder or contributor is granted under this license, whether expressly, by implication, estoppel or otherwise.
|
|
12
|
+
|
|
13
|
+
DISCLAIMER
|
|
14
|
+
|
|
15
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# @vltpkg/dss-parser
|
|
2
|
+
|
|
3
|
+
The Dependency Selector Syntax parser used by the vlt client.
|
|
4
|
+
|
|
5
|
+
Uses
|
|
6
|
+
[postcss-selector-parser](https://github.com/postcss/postcss-selector-parser)
|
|
7
|
+
to parse a selector string into an AST.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
import { parse } from '@vltpkg/dss-parser'
|
|
13
|
+
|
|
14
|
+
// Parse a selector string into an AST
|
|
15
|
+
const ast = parse(':root > *')
|
|
16
|
+
```
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,93 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,MAAM,yBAAyB,CAAA;AAE3D,OAAO,EACL,cAAc,EACd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CAAA;AAClE,CAAC,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"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Tag, String, Selector, Root, Pseudo, Nesting, Identifier, Comment, Combinator, ClassName, Attribute, Universal } from 'postcss-selector-parser';
|
|
2
|
+
export type PostcssNode = Tag | String | Selector | Root | Pseudo | Nesting | Identifier | Comment | Combinator | ClassName | Attribute | Universal;
|
|
3
|
+
export type PostcssNodeWithChildren = Selector | Root | Pseudo;
|
|
4
|
+
export type ParsedSelectorToken = PostcssNode & {
|
|
5
|
+
token: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const isPostcssNodeWithChildren: (node: any) => node is PostcssNodeWithChildren;
|
|
8
|
+
export declare const asPostcssNodeWithChildren: (node?: PostcssNode) => PostcssNodeWithChildren;
|
|
9
|
+
export declare const isAttributeNode: (node: unknown) => node is Attribute;
|
|
10
|
+
export declare const asAttributeNode: (node?: PostcssNode) => Attribute;
|
|
11
|
+
export declare const isCombinatorNode: (node: unknown) => node is Combinator;
|
|
12
|
+
export declare const asCombinatorNode: (node?: PostcssNode) => Combinator;
|
|
13
|
+
export declare const isIdentifierNode: (node: any) => node is Identifier;
|
|
14
|
+
export declare const asIdentifierNode: (node?: PostcssNode) => Identifier;
|
|
15
|
+
export declare const isSelectorNode: (node: any) => node is Selector;
|
|
16
|
+
export declare const asSelectorNode: (node?: PostcssNode) => Selector;
|
|
17
|
+
export declare const isPseudoNode: (node: unknown) => node is Pseudo;
|
|
18
|
+
export declare const asPseudoNode: (node?: PostcssNode) => Pseudo;
|
|
19
|
+
export declare const isTagNode: (node: unknown) => node is Tag;
|
|
20
|
+
export declare const asTagNode: (node?: PostcssNode) => Tag;
|
|
21
|
+
export declare const isStringNode: (node: unknown) => node is String;
|
|
22
|
+
export declare const asStringNode: (node?: PostcssNode) => String;
|
|
23
|
+
export declare const isCommentNode: (node: unknown) => node is Comment;
|
|
24
|
+
export declare const asCommentNode: (node?: PostcssNode) => Comment;
|
|
25
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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,EACV,MAAM,yBAAyB,CAAA;AAEhC,MAAM,MAAM,WAAW,GACnB,GAAG,GACH,MAAM,GACN,QAAQ,GACR,IAAI,GACJ,MAAM,GACN,OAAO,GACP,UAAU,GACV,OAAO,GACP,UAAU,GACV,SAAS,GACT,SAAS,GACT,SAAS,CAAA;AAEb,MAAM,MAAM,uBAAuB,GAAG,QAAQ,GAAG,IAAI,GAAG,MAAM,CAAA;AAE9D,MAAM,MAAM,mBAAmB,GAA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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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAoC3C,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,IAAS,EACwB,EAAE,CACnC,MAAM,IAAI,IAAI,IAAI,OAAO,IAAI,IAAI,CAAA;AAEnC,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,IAAkB,EACO,EAAE;IAC3B,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,KAAK,CAAC,uBAAuB,CAAC,CAAA;IACtC,CAAC;IAED,IAAI,CAAC,yBAAyB,CAAC,IAAI,CAAC,EAAE,CAAC;QACrC,MAAM,KAAK,CAAC,yCAAyC,EAAE;YACrD,KAAK,EAAE,IAAI;SACZ,CAAC,CAAA;IACJ,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAED,MAAM,KAAK,GAAG,CAAC,CAAU,EAAgC,EAAE,CACzD,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,CAAA;AAE9B,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,IAAa,EAAqB,EAAE,CAClE,KAAK,CAAC,IAAI,CAAC,IAAI,CAA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AAA;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} 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 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"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vltpkg/dss-parser",
|
|
3
|
+
"description": "The Dependency Selector Syntax (DSS) parser",
|
|
4
|
+
"version": "0.0.0-14",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/vltpkg/vltpkg.git",
|
|
8
|
+
"directory": "src/dss-parser"
|
|
9
|
+
},
|
|
10
|
+
"tshy": {
|
|
11
|
+
"selfLink": false,
|
|
12
|
+
"liveDev": true,
|
|
13
|
+
"dialects": [
|
|
14
|
+
"esm"
|
|
15
|
+
],
|
|
16
|
+
"exports": {
|
|
17
|
+
"./package.json": "./package.json",
|
|
18
|
+
".": "./src/index.ts"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"postcss-selector-parser": "^7.1.0",
|
|
23
|
+
"@vltpkg/error-cause": "0.0.0-14"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@eslint/js": "^9.28.0",
|
|
27
|
+
"@types/node": "^22.15.29",
|
|
28
|
+
"eslint": "^9.28.0",
|
|
29
|
+
"prettier": "^3.5.3",
|
|
30
|
+
"tap": "^21.1.0",
|
|
31
|
+
"tshy": "^3.0.2",
|
|
32
|
+
"typedoc": "~0.27.9",
|
|
33
|
+
"typescript": "5.7.3",
|
|
34
|
+
"typescript-eslint": "^8.33.1"
|
|
35
|
+
},
|
|
36
|
+
"license": "BSD-2-Clause-Patent",
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=22"
|
|
39
|
+
},
|
|
40
|
+
"tap": {
|
|
41
|
+
"extends": "../../tap-config.yaml"
|
|
42
|
+
},
|
|
43
|
+
"prettier": "../../.prettierrc.js",
|
|
44
|
+
"module": "./dist/esm/index.js",
|
|
45
|
+
"type": "module",
|
|
46
|
+
"exports": {
|
|
47
|
+
"./package.json": "./package.json",
|
|
48
|
+
".": {
|
|
49
|
+
"import": {
|
|
50
|
+
"types": "./dist/esm/index.d.ts",
|
|
51
|
+
"default": "./dist/esm/index.js"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"files": [
|
|
56
|
+
"dist"
|
|
57
|
+
],
|
|
58
|
+
"scripts": {
|
|
59
|
+
"format": "prettier --write . --log-level warn --ignore-path ../../.prettierignore --cache",
|
|
60
|
+
"format:check": "prettier --check . --ignore-path ../../.prettierignore --cache",
|
|
61
|
+
"lint": "eslint . --fix",
|
|
62
|
+
"lint:check": "eslint .",
|
|
63
|
+
"snap": "tap",
|
|
64
|
+
"test": "tap",
|
|
65
|
+
"posttest": "tsc --noEmit",
|
|
66
|
+
"tshy": "tshy",
|
|
67
|
+
"typecheck": "tsc --noEmit"
|
|
68
|
+
}
|
|
69
|
+
}
|