Skip to content

Commit 8233fca

Browse files
authored
fix(arborist): fix bare attribute queries (#5248)
1 parent d55007d commit 8233fca

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

workspaces/arborist/lib/query-selector-all.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,6 @@ class Results {
317317

318318
// operators for attribute selectors
319319
const attributeOperators = {
320-
// existence of the attribute
321-
'' ({ attr }) {
322-
return Boolean(attr)
323-
},
324320
// attribute value is equivalent
325321
'=' ({ attr, value, insensitive }) {
326322
return attr === value
@@ -370,6 +366,10 @@ const attributeMatch = (matcher, obj) => {
370366
const operator = matcher.operator || ''
371367
const attribute = matcher.qualifiedAttribute
372368
let value = matcher.value || ''
369+
// return early if checking existence
370+
if (operator === '') {
371+
return Boolean(obj[attribute])
372+
}
373373
if (insensitive) {
374374
value = value.toLowerCase()
375375
}

workspaces/arborist/test/query-selector-all.js

+6
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ t.test('query-selector-all', async t => {
8686
dependencies: {
8787
lorem: 'latest',
8888
},
89+
scripts: {
90+
test: 'tap',
91+
},
8992
}),
9093
},
9194
foo: {
@@ -567,6 +570,9 @@ t.test('query-selector-all', async t => {
567570
[':attr(arbitrary, :attr([foo=10000]))', ['[email protected]']],
568571

569572
// attribute matchers
573+
['[scripts]', [
574+
575+
]],
570576
['[name]', [
571577
572578

0 commit comments

Comments
 (0)