Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -373,6 +369,10 @@ const attributeMatch = (matcher, obj) => {
if (insensitive) {
value = value.toLowerCase()
}
// if we're checking for existence we can return early & avoid attr coersion
if (operator === '') {
return Boolean(obj[attribute])
}
// in case the current object is an array
// then we try to match every item in the array
if (Array.isArray(obj[attribute])) {
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