Skip to content

Commit

Permalink
fix(arborist): fix bare attribute queries (#5248)
Browse files Browse the repository at this point in the history
  • Loading branch information
darcyclarke authored Aug 3, 2022
1 parent d55007d commit 8233fca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 4 additions & 4 deletions workspaces/arborist/lib/query-selector-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,6 @@ class Results {

// operators for attribute selectors
const attributeOperators = {
// existence of the attribute
'' ({ attr }) {
return Boolean(attr)
},
// attribute value is equivalent
'=' ({ attr, value, insensitive }) {
return attr === value
Expand Down Expand Up @@ -370,6 +366,10 @@ const attributeMatch = (matcher, obj) => {
const operator = matcher.operator || ''
const attribute = matcher.qualifiedAttribute
let value = matcher.value || ''
// return early if checking existence
if (operator === '') {
return Boolean(obj[attribute])
}
if (insensitive) {
value = value.toLowerCase()
}
Expand Down
6 changes: 6 additions & 0 deletions workspaces/arborist/test/query-selector-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ t.test('query-selector-all', async t => {
dependencies: {
lorem: 'latest',
},
scripts: {
test: 'tap',
},
}),
},
foo: {
Expand Down Expand Up @@ -567,6 +570,9 @@ t.test('query-selector-all', async t => {
[':attr(arbitrary, :attr([foo=10000]))', ['bar@2.0.0']],

// attribute matchers
['[scripts]', [
'baz@1.0.0',
]],
['[name]', [
'query-selector-all-tests@1.0.0',
'a@1.0.0',
Expand Down

0 comments on commit 8233fca

Please sign in to comment.