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 => {
│ └── lorem@1.0.0 (production dep of baz)
├── abbrev@1.1.1 (production dep of query-selector-all-tests)
├─┬ b@1.0.0 -> ./b (workspace)
│ ├── a@2.0.0 (dev dep of b, deduped)
│ └── bar@2.0.0 (production dep of b, deduped)
├─┬ bar@2.0.0 (production dep of query-selector-all-tests)
│ └── moo@3.0.0 (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))', ['foo@2.2.2']],
['*:has(> #bar:semver(1.4.0))', ['foo@2.2.2']],
['.workspace:has(> * > #lorem)', ['a@1.0.0']],
['.workspace:has(* #lorem, ~ #b)', ['a@1.0.0']],
['.workspace:has(* #lorem, ~ #b)', ['a@1.0.0', 'b@1.0.0']],

// is pseudo
[':is(#a, #b) > *', ['a@1.0.0', 'bar@2.0.0', 'baz@1.0.0']],
Expand Down Expand Up @@ -960,5 +961,6 @@ t.test('query-selector-all', async t => {
[':root #bar:semver(1) ~ *', ['dash-separated-pkg@1.0.0']],
['#bar:semver(2), #foo', ['bar@2.0.0', 'foo@2.2.2']],
['#a, #bar:semver(2), #foo:semver(2.2.2)', ['a@1.0.0', 'bar@2.0.0', 'foo@2.2.2']],
['#b *', ['a@1.0.0', 'bar@2.0.0', 'baz@1.0.0', 'lorem@1.0.0', 'moo@3.0.0']],
])
})