Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion workspaces/arborist/lib/query-selector-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,10 @@ const hasAscendant = (node, compareNodes, seen = new Set()) => {
}

if (node.isTop && node.resolveParent) {
return hasAscendant(node.resolveParent, compareNodes)
/* istanbul ignore if - investigate if linksIn check obviates need for this */
if (hasAscendant(node.resolveParent, compareNodes)) {
return true
}
}
for (const edge of node.edgesIn) {
// TODO Need a test with an infinite loop
Expand All @@ -731,6 +734,11 @@ const hasAscendant = (node, compareNodes, seen = new Set()) => {
return true
}
}
for (const linkNode of node.linksIn) {
if (hasAscendant(linkNode, compareNodes, seen)) {
return true
}
}
return false
}

Expand Down
4 changes: 3 additions & 1 deletion workspaces/arborist/test/query-selector-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ t.test('query-selector-all', async t => {
│ └── [email protected] (production dep of baz)
├── [email protected] (production dep of query-selector-all-tests)
├─┬ [email protected] -> ./b (workspace)
│ ├── [email protected] (dev dep of b, deduped)
│ └── [email protected] (production dep of b, deduped)
├─┬ [email protected] (production dep of query-selector-all-tests)
│ └── [email protected] (production dep of bar)
Expand Down Expand Up @@ -513,7 +514,7 @@ t.test('query-selector-all', async t => {
['*:has(* > #bar:semver(1.4.0))', ['[email protected]']],
['*:has(> #bar:semver(1.4.0))', ['[email protected]']],
['.workspace:has(> * > #lorem)', ['[email protected]']],
['.workspace:has(* #lorem, ~ #b)', ['[email protected]']],
['.workspace:has(* #lorem, ~ #b)', ['[email protected]', '[email protected]']],

// is pseudo
[':is(#a, #b) > *', ['[email protected]', '[email protected]', '[email protected]']],
Expand Down Expand Up @@ -960,5 +961,6 @@ t.test('query-selector-all', async t => {
[':root #bar:semver(1) ~ *', ['[email protected]']],
['#bar:semver(2), #foo', ['[email protected]', '[email protected]']],
['#a, #bar:semver(2), #foo:semver(2.2.2)', ['[email protected]', '[email protected]', '[email protected]']],
['#b *', ['[email protected]', '[email protected]', '[email protected]', '[email protected]', '[email protected]']],
])
})