@vltpkg/query 1.4.0 → 1.6.0
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/dist/index.d.ts +7 -2
- package/dist/index.js +23 -4
- package/dist/pseudo/skill.d.ts +7 -0
- package/dist/pseudo/skill.js +52 -0
- package/dist/pseudo/skills.d.ts +6 -0
- package/dist/pseudo/skills.js +26 -0
- package/dist/pseudo.js +7 -0
- package/dist/types.d.ts +29 -1
- package/package.json +10 -12
- package/skills/dss-query/REFERENCE.md +0 -123
- package/skills/dss-query/SKILL.md +0 -190
- package/skills/dss-query/evals/README.md +0 -81
- package/skills/dss-query/evals/evals.json +0 -89
- package/skills/dss-query/evals/grade.mjs +0 -481
- package/src/attribute.ts +0 -190
- package/src/combinator.ts +0 -135
- package/src/error.ts +0 -78
- package/src/id.ts +0 -46
- package/src/index.ts +0 -640
- package/src/parser.ts +0 -122
- package/src/pseudo/abandoned.ts +0 -9
- package/src/pseudo/attr.ts +0 -92
- package/src/pseudo/built.ts +0 -19
- package/src/pseudo/confused.ts +0 -29
- package/src/pseudo/cve.ts +0 -93
- package/src/pseudo/cwe.ts +0 -97
- package/src/pseudo/debug.ts +0 -9
- package/src/pseudo/deprecated.ts +0 -9
- package/src/pseudo/dev.ts +0 -18
- package/src/pseudo/diff.ts +0 -90
- package/src/pseudo/dist.ts +0 -148
- package/src/pseudo/dynamic.ts +0 -9
- package/src/pseudo/empty.ts +0 -15
- package/src/pseudo/entropic.ts +0 -9
- package/src/pseudo/env.ts +0 -6
- package/src/pseudo/eval.ts +0 -9
- package/src/pseudo/fs.ts +0 -9
- package/src/pseudo/helpers.ts +0 -106
- package/src/pseudo/host.ts +0 -111
- package/src/pseudo/hostname.ts +0 -156
- package/src/pseudo/license.ts +0 -134
- package/src/pseudo/link.ts +0 -30
- package/src/pseudo/malware.ts +0 -41
- package/src/pseudo/minified.ts +0 -9
- package/src/pseudo/missing.ts +0 -16
- package/src/pseudo/native.ts +0 -9
- package/src/pseudo/network.ts +0 -9
- package/src/pseudo/obfuscated.ts +0 -9
- package/src/pseudo/optional.ts +0 -18
- package/src/pseudo/outdated.ts +0 -345
- package/src/pseudo/overridden.ts +0 -20
- package/src/pseudo/path.ts +0 -146
- package/src/pseudo/peer.ts +0 -18
- package/src/pseudo/prerelease.ts +0 -47
- package/src/pseudo/private.ts +0 -19
- package/src/pseudo/prod.ts +0 -18
- package/src/pseudo/published.ts +0 -250
- package/src/pseudo/registry.ts +0 -29
- package/src/pseudo/root.ts +0 -19
- package/src/pseudo/scanned.ts +0 -20
- package/src/pseudo/score.ts +0 -186
- package/src/pseudo/scripts.ts +0 -61
- package/src/pseudo/semver.ts +0 -320
- package/src/pseudo/severity.ts +0 -231
- package/src/pseudo/shell.ts +0 -9
- package/src/pseudo/shrinkwrap.ts +0 -9
- package/src/pseudo/spec.ts +0 -131
- package/src/pseudo/squat.ts +0 -225
- package/src/pseudo/suspicious.ts +0 -9
- package/src/pseudo/tracker.ts +0 -9
- package/src/pseudo/trivial.ts +0 -9
- package/src/pseudo/type.ts +0 -26
- package/src/pseudo/undesirable.ts +0 -9
- package/src/pseudo/unknown.ts +0 -9
- package/src/pseudo/unmaintained.ts +0 -9
- package/src/pseudo/unpopular.ts +0 -9
- package/src/pseudo/unstable.ts +0 -9
- package/src/pseudo/vuln.ts +0 -273
- package/src/pseudo/workspace.ts +0 -22
- package/src/pseudo.ts +0 -433
- package/src/types.ts +0 -176
- package/tap-snapshots/test/attribute.ts.test.cjs +0 -304
- package/tap-snapshots/test/combinator.ts.test.cjs +0 -333
- package/tap-snapshots/test/id.ts.test.cjs +0 -118
- package/tap-snapshots/test/parser.ts.test.cjs +0 -344
- package/tap-snapshots/test/pseudo/abandoned.ts.test.cjs +0 -18
- package/tap-snapshots/test/pseudo/attr.ts.test.cjs +0 -161
- package/tap-snapshots/test/pseudo/built.ts.test.cjs +0 -70
- package/tap-snapshots/test/pseudo/confused.ts.test.cjs +0 -32
- package/tap-snapshots/test/pseudo/cve.ts.test.cjs +0 -49
- package/tap-snapshots/test/pseudo/cwe.ts.test.cjs +0 -49
- package/tap-snapshots/test/pseudo/debug.ts.test.cjs +0 -18
- package/tap-snapshots/test/pseudo/deprecated.ts.test.cjs +0 -18
- package/tap-snapshots/test/pseudo/dist.ts.test.cjs +0 -30
- package/tap-snapshots/test/pseudo/dynamic.ts.test.cjs +0 -18
- package/tap-snapshots/test/pseudo/empty.ts.test.cjs +0 -50
- package/tap-snapshots/test/pseudo/entropic.ts.test.cjs +0 -18
- package/tap-snapshots/test/pseudo/env.ts.test.cjs +0 -18
- package/tap-snapshots/test/pseudo/eval.ts.test.cjs +0 -18
- package/tap-snapshots/test/pseudo/fs.ts.test.cjs +0 -18
- package/tap-snapshots/test/pseudo/helpers.ts.test.cjs +0 -18
- package/tap-snapshots/test/pseudo/hostname.ts.test.cjs +0 -148
- package/tap-snapshots/test/pseudo/license.ts.test.cjs +0 -41
- package/tap-snapshots/test/pseudo/link.ts.test.cjs +0 -36
- package/tap-snapshots/test/pseudo/malware.ts.test.cjs +0 -22
- package/tap-snapshots/test/pseudo/minified.ts.test.cjs +0 -18
- package/tap-snapshots/test/pseudo/missing.ts.test.cjs +0 -30
- package/tap-snapshots/test/pseudo/native.ts.test.cjs +0 -18
- package/tap-snapshots/test/pseudo/network.ts.test.cjs +0 -18
- package/tap-snapshots/test/pseudo/obfuscated.ts.test.cjs +0 -18
- package/tap-snapshots/test/pseudo/outdated.ts.test.cjs +0 -132
- package/tap-snapshots/test/pseudo/overridden.ts.test.cjs +0 -75
- package/tap-snapshots/test/pseudo/prerelease.ts.test.cjs +0 -101
- package/tap-snapshots/test/pseudo/private.ts.test.cjs +0 -38
- package/tap-snapshots/test/pseudo/published.ts.test.cjs +0 -171
- package/tap-snapshots/test/pseudo/registry.ts.test.cjs +0 -68
- package/tap-snapshots/test/pseudo/root.ts.test.cjs +0 -24
- package/tap-snapshots/test/pseudo/scanned.ts.test.cjs +0 -18
- package/tap-snapshots/test/pseudo/score.ts.test.cjs +0 -239
- package/tap-snapshots/test/pseudo/scripts.ts.test.cjs +0 -62
- package/tap-snapshots/test/pseudo/semver.ts.test.cjs +0 -575
- package/tap-snapshots/test/pseudo/severity.ts.test.cjs +0 -122
- package/tap-snapshots/test/pseudo/shell.ts.test.cjs +0 -18
- package/tap-snapshots/test/pseudo/shrinkwrap.ts.test.cjs +0 -18
- package/tap-snapshots/test/pseudo/spec.ts.test.cjs +0 -148
- package/tap-snapshots/test/pseudo/squat.ts.test.cjs +0 -129
- package/tap-snapshots/test/pseudo/suspicious.ts.test.cjs +0 -18
- package/tap-snapshots/test/pseudo/tracker.ts.test.cjs +0 -18
- package/tap-snapshots/test/pseudo/trivial.ts.test.cjs +0 -18
- package/tap-snapshots/test/pseudo/type.ts.test.cjs +0 -51
- package/tap-snapshots/test/pseudo/undesirable.ts.test.cjs +0 -18
- package/tap-snapshots/test/pseudo/unknown.ts.test.cjs +0 -18
- package/tap-snapshots/test/pseudo/unmaintained.ts.test.cjs +0 -18
- package/tap-snapshots/test/pseudo/unpopular.ts.test.cjs +0 -18
- package/tap-snapshots/test/pseudo/unstable.ts.test.cjs +0 -18
- package/tap-snapshots/test/pseudo/vuln.ts.test.cjs +0 -208
- package/tap-snapshots/test/pseudo/vulnerable.ts.test.cjs +0 -20
- package/tap-snapshots/test/pseudo/workspace.ts.test.cjs +0 -19
- package/tap-snapshots/test/pseudo.ts.test.cjs +0 -1247
- package/test/attribute.ts +0 -273
- package/test/combinator.ts +0 -175
- package/test/error.ts +0 -60
- package/test/fixtures/graph.ts +0 -999
- package/test/fixtures/selector.ts +0 -103
- package/test/fixtures/types.ts +0 -7
- package/test/id.ts +0 -102
- package/test/index.ts +0 -1049
- package/test/parser.ts +0 -117
- package/test/pseudo/abandoned.ts +0 -98
- package/test/pseudo/attr.ts +0 -298
- package/test/pseudo/built.ts +0 -214
- package/test/pseudo/confused.ts +0 -160
- package/test/pseudo/cve.ts +0 -249
- package/test/pseudo/cwe.ts +0 -255
- package/test/pseudo/debug.ts +0 -98
- package/test/pseudo/deprecated.ts +0 -98
- package/test/pseudo/dev.ts +0 -61
- package/test/pseudo/diff.ts +0 -417
- package/test/pseudo/dist.ts +0 -215
- package/test/pseudo/dynamic.ts +0 -98
- package/test/pseudo/empty.ts +0 -108
- package/test/pseudo/entropic.ts +0 -101
- package/test/pseudo/env.ts +0 -98
- package/test/pseudo/eval.ts +0 -98
- package/test/pseudo/fs.ts +0 -98
- package/test/pseudo/helpers.ts +0 -370
- package/test/pseudo/host-context.ts +0 -276
- package/test/pseudo/hostname.ts +0 -314
- package/test/pseudo/license.ts +0 -265
- package/test/pseudo/link.ts +0 -94
- package/test/pseudo/malware.ts +0 -184
- package/test/pseudo/minified.ts +0 -98
- package/test/pseudo/missing.ts +0 -111
- package/test/pseudo/native.ts +0 -98
- package/test/pseudo/network.ts +0 -98
- package/test/pseudo/obfuscated.ts +0 -98
- package/test/pseudo/optional.ts +0 -73
- package/test/pseudo/outdated.ts +0 -461
- package/test/pseudo/overridden.ts +0 -317
- package/test/pseudo/path.ts +0 -680
- package/test/pseudo/peer.ts +0 -101
- package/test/pseudo/prerelease.ts +0 -279
- package/test/pseudo/private.ts +0 -108
- package/test/pseudo/prod.ts +0 -61
- package/test/pseudo/published.ts +0 -557
- package/test/pseudo/registry.ts +0 -122
- package/test/pseudo/root.ts +0 -66
- package/test/pseudo/scanned.ts +0 -144
- package/test/pseudo/score.ts +0 -591
- package/test/pseudo/scripts.ts +0 -324
- package/test/pseudo/semver.ts +0 -822
- package/test/pseudo/severity.ts +0 -342
- package/test/pseudo/shell.ts +0 -98
- package/test/pseudo/shrinkwrap.ts +0 -98
- package/test/pseudo/spec.ts +0 -525
- package/test/pseudo/squat.ts +0 -565
- package/test/pseudo/suspicious.ts +0 -98
- package/test/pseudo/tracker.ts +0 -98
- package/test/pseudo/trivial.ts +0 -98
- package/test/pseudo/type.ts +0 -105
- package/test/pseudo/undesirable.ts +0 -98
- package/test/pseudo/unknown.ts +0 -98
- package/test/pseudo/unmaintained.ts +0 -98
- package/test/pseudo/unpopular.ts +0 -98
- package/test/pseudo/unstable.ts +0 -98
- package/test/pseudo/vuln.ts +0 -625
- package/test/pseudo/vulnerable.ts +0 -137
- package/test/pseudo/workspace.ts +0 -111
- package/test/pseudo.ts +0 -584
- package/tsconfig.json +0 -3
- package/tsconfig.publish.json +0 -19
- package/tsconfig.publish.tsbuildinfo +0 -1
- package/typedoc.mjs +0 -2
package/src/combinator.ts
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import { asCombinatorNode } from '@vltpkg/dss-parser'
|
|
2
|
-
import { queryError } from './error.ts'
|
|
3
|
-
import type { CombinatorName } from '@vltpkg/dss-parser'
|
|
4
|
-
import type { EdgeLike, NodeLike } from '@vltpkg/types'
|
|
5
|
-
import type { ParserState, ParserFn } from './types.ts'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Returns a new set of nodes, containing all direct dependencies
|
|
9
|
-
* of the current list of nodes used.
|
|
10
|
-
*
|
|
11
|
-
* ref: https://developer.mozilla.org/en-US/docs/Web/CSS/Child_combinator
|
|
12
|
-
*/
|
|
13
|
-
const childCombinator = async (state: ParserState) => {
|
|
14
|
-
const traverse = new Set(state.partial.nodes)
|
|
15
|
-
state.partial.edges.clear()
|
|
16
|
-
state.partial.nodes.clear()
|
|
17
|
-
|
|
18
|
-
// visit direct children of the current list of nodes
|
|
19
|
-
// collecting refs to these children and the edges that
|
|
20
|
-
// connected them.
|
|
21
|
-
for (const node of traverse) {
|
|
22
|
-
for (const edge of node.edgesOut.values()) {
|
|
23
|
-
if (edge.to) {
|
|
24
|
-
state.partial.edges.add(edge)
|
|
25
|
-
state.partial.nodes.add(edge.to)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return state
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Returns a new set of nodes, containing nodes that are also children
|
|
35
|
-
* of all parent nodes to the current list of nodes used.
|
|
36
|
-
*
|
|
37
|
-
* Note: The subsequent-sibling comparator has a behavior that is
|
|
38
|
-
* somehow approximative of that of its css counterpart, given that
|
|
39
|
-
* in the context of dependency graphs the order of appearance is
|
|
40
|
-
* not necessarily controlled by the end user. The approach for
|
|
41
|
-
* this comparator is to match all siblings of a node.
|
|
42
|
-
*
|
|
43
|
-
* ref: https://developer.mozilla.org/en-US/docs/Web/CSS/Subsequent-sibling_combinator
|
|
44
|
-
*/
|
|
45
|
-
const subsequentSiblingCombinator = async (state: ParserState) => {
|
|
46
|
-
const traverse = new Set(state.partial.nodes)
|
|
47
|
-
state.partial.edges.clear()
|
|
48
|
-
state.partial.nodes.clear()
|
|
49
|
-
|
|
50
|
-
// visits direct parents of the current list of node and then
|
|
51
|
-
// visit their children, collecting refs to all children and edges
|
|
52
|
-
// that are not in the original list of nodes.
|
|
53
|
-
for (const node of traverse) {
|
|
54
|
-
for (const edge of node.edgesIn) {
|
|
55
|
-
const parents: IterableIterator<EdgeLike> =
|
|
56
|
-
edge.from.edgesOut.values()
|
|
57
|
-
for (const edge of parents) {
|
|
58
|
-
if (edge.to && edge.to !== node) {
|
|
59
|
-
state.partial.edges.add(edge)
|
|
60
|
-
state.partial.nodes.add(edge.to)
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return state
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Returns a new set of nodes containing all nodes that are descendents
|
|
71
|
-
* to items in the current list of nodes.
|
|
72
|
-
*
|
|
73
|
-
* ref: https://developer.mozilla.org/en-US/docs/Web/CSS/Descendant_combinator
|
|
74
|
-
*/
|
|
75
|
-
const descendentCombinator = async (state: ParserState) => {
|
|
76
|
-
// spaces between tags selectors are a noop
|
|
77
|
-
if (state.prev?.type === 'tag' || state.next?.type === 'tag') {
|
|
78
|
-
return state
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const traverse = new Set<NodeLike>(state.partial.nodes)
|
|
82
|
-
state.partial.edges.clear()
|
|
83
|
-
state.partial.nodes.clear()
|
|
84
|
-
|
|
85
|
-
// breadth-first traversal of the graph, starting from the current
|
|
86
|
-
// list of nodes, collecting all nodes and edges along the way
|
|
87
|
-
for (const node of traverse) {
|
|
88
|
-
const children = new Set<NodeLike>()
|
|
89
|
-
for (const edge of node.edgesOut.values()) {
|
|
90
|
-
if (edge.to) {
|
|
91
|
-
children.add(edge.to)
|
|
92
|
-
state.partial.edges.add(edge)
|
|
93
|
-
state.partial.nodes.add(edge.to)
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
for (const child of children) {
|
|
97
|
-
traverse.add(child)
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return state
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const combinatorSelectors = {
|
|
105
|
-
'>': childCombinator,
|
|
106
|
-
'~': subsequentSiblingCombinator,
|
|
107
|
-
' ': descendentCombinator,
|
|
108
|
-
} satisfies Record<CombinatorName, ParserFn>
|
|
109
|
-
|
|
110
|
-
const combinatorSelectorsMap = new Map<string, ParserFn>(
|
|
111
|
-
Object.entries(combinatorSelectors),
|
|
112
|
-
)
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Parse css-style combinators, e.g: `>`, `~` and ` `
|
|
116
|
-
*/
|
|
117
|
-
export const combinator = async (state: ParserState) => {
|
|
118
|
-
await state.cancellable()
|
|
119
|
-
|
|
120
|
-
const curr = asCombinatorNode(state.current)
|
|
121
|
-
const parserFn =
|
|
122
|
-
curr.value && combinatorSelectorsMap.get(curr.value)
|
|
123
|
-
if (!parserFn) {
|
|
124
|
-
if (state.loose) {
|
|
125
|
-
return state
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
throw queryError(
|
|
129
|
-
`Unsupported combinator: ${state.current.value}`,
|
|
130
|
-
state.current,
|
|
131
|
-
{ validOptions: [...combinatorSelectorsMap.keys()] },
|
|
132
|
-
)
|
|
133
|
-
}
|
|
134
|
-
return parserFn(state)
|
|
135
|
-
}
|
package/src/error.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { error } from '@vltpkg/error-cause'
|
|
2
|
-
import type { ErrorCauseOptions } from '@vltpkg/error-cause'
|
|
3
|
-
import type { PostcssNode } from '@vltpkg/dss-parser'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* The source text of a selector node. Parsed nodes hold references to
|
|
7
|
-
* their parents, so they can never be used as an error `found` value:
|
|
8
|
-
* printing one dumps the entire circular selector tree.
|
|
9
|
-
*/
|
|
10
|
-
export const selectorText = (node: PostcssNode): string => {
|
|
11
|
-
// parsed nodes stringify back to their source. anything else (a
|
|
12
|
-
// hand-built node in a test, say) only has its value to go on.
|
|
13
|
-
const text =
|
|
14
|
-
node.toString === Object.prototype.toString ?
|
|
15
|
-
''
|
|
16
|
-
// postcss escapes characters it does not expect in a value, e.g.
|
|
17
|
-
// the leading `.` of `.dev`, which parses as an escaped tag.
|
|
18
|
-
: String(node).trim().replace(/\\(.)/g, '$1')
|
|
19
|
-
return text || (node.value ?? node.type)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* A query syntax error, carrying the offending selector as a string and
|
|
24
|
-
* an `EQUERY` code so the CLI can print it as a usage problem instead
|
|
25
|
-
* of an internal failure.
|
|
26
|
-
*/
|
|
27
|
-
export const queryError = (
|
|
28
|
-
message: string,
|
|
29
|
-
node: PostcssNode,
|
|
30
|
-
extra?: Pick<ErrorCauseOptions, 'wanted' | 'validOptions'>,
|
|
31
|
-
) =>
|
|
32
|
-
error(message, {
|
|
33
|
-
code: 'EQUERY',
|
|
34
|
-
found: selectorText(node),
|
|
35
|
-
...extra,
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Number of single-character edits between two strings, capped at
|
|
40
|
-
* `max` so a long list of candidates stays cheap to scan.
|
|
41
|
-
*/
|
|
42
|
-
const distance = (a: string, b: string, max: number): number => {
|
|
43
|
-
if (Math.abs(a.length - b.length) > max) return max + 1
|
|
44
|
-
let prev = Array.from({ length: b.length + 1 }, (_, i) => i)
|
|
45
|
-
for (let i = 1; i <= a.length; i++) {
|
|
46
|
-
const row = [i]
|
|
47
|
-
let best = i
|
|
48
|
-
for (let j = 1; j <= b.length; j++) {
|
|
49
|
-
const cost = a[i - 1] === b[j - 1] ? 0 : 1
|
|
50
|
-
/* c8 ignore next 5 -- indexes are always in range here */
|
|
51
|
-
const d = Math.min(
|
|
52
|
-
(row[j - 1] ?? 0) + 1,
|
|
53
|
-
(prev[j] ?? 0) + 1,
|
|
54
|
-
(prev[j - 1] ?? 0) + cost,
|
|
55
|
-
)
|
|
56
|
-
row.push(d)
|
|
57
|
-
if (d < best) best = d
|
|
58
|
-
}
|
|
59
|
-
if (best > max) return max + 1
|
|
60
|
-
prev = row
|
|
61
|
-
}
|
|
62
|
-
/* c8 ignore next -- the loop always fills the last cell */
|
|
63
|
-
return prev[b.length] ?? max + 1
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Candidates that are a typo away from `value`, closest first.
|
|
68
|
-
*/
|
|
69
|
-
export const didYouMean = (
|
|
70
|
-
value: string,
|
|
71
|
-
candidates: Iterable<string>,
|
|
72
|
-
max = 2,
|
|
73
|
-
): string[] =>
|
|
74
|
-
[...candidates]
|
|
75
|
-
.map(c => [c, distance(value, c, max)] as const)
|
|
76
|
-
.filter(([, d]) => d <= max)
|
|
77
|
-
.sort(([a, x], [b, y]) => x - y || a.localeCompare(b, 'en'))
|
|
78
|
-
.map(([c]) => c)
|
package/src/id.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { asIdentifierNode } from '@vltpkg/dss-parser'
|
|
2
|
-
import { error } from '@vltpkg/error-cause'
|
|
3
|
-
import type { ParserState } from './types.ts'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Parse ids, e.g: `#foo`
|
|
7
|
-
*/
|
|
8
|
-
export const id = async (
|
|
9
|
-
state: ParserState,
|
|
10
|
-
): Promise<ParserState> => {
|
|
11
|
-
const { value } = asIdentifierNode(state.current)
|
|
12
|
-
|
|
13
|
-
/* c8 ignore start - should not be possible */
|
|
14
|
-
if (!value) {
|
|
15
|
-
throw error('Missing identifier name')
|
|
16
|
-
}
|
|
17
|
-
/* c8 ignore stop */
|
|
18
|
-
|
|
19
|
-
// Filter out any edges and their linked
|
|
20
|
-
// nodes if they don't match the id value
|
|
21
|
-
for (const edge of state.partial.edges) {
|
|
22
|
-
if (edge.name !== value) {
|
|
23
|
-
state.partial.edges.delete(edge)
|
|
24
|
-
if (edge.to) {
|
|
25
|
-
state.partial.nodes.delete(edge.to)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// Filter out importer nodes, this extra step is needed
|
|
31
|
-
// to filter out nodes that have no edges linking to them
|
|
32
|
-
for (const node of state.partial.nodes) {
|
|
33
|
-
if (
|
|
34
|
-
node.edgesIn.size === 0 &&
|
|
35
|
-
node.name !== value &&
|
|
36
|
-
state.partial.nodes.has(node)
|
|
37
|
-
) {
|
|
38
|
-
state.partial.nodes.delete(node)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Increment the idCounter for specificity
|
|
43
|
-
state.specificity.idCounter += 1
|
|
44
|
-
|
|
45
|
-
return state
|
|
46
|
-
}
|