diff --git a/workspaces/arborist/lib/query-selector-all.js b/workspaces/arborist/lib/query-selector-all.js index f4903f3e2009b..6c540dea3c872 100644 --- a/workspaces/arborist/lib/query-selector-all.js +++ b/workspaces/arborist/lib/query-selector-all.js @@ -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 @@ -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() } diff --git a/workspaces/arborist/test/query-selector-all.js b/workspaces/arborist/test/query-selector-all.js index ec8c116122099..c335a82cbaf4b 100644 --- a/workspaces/arborist/test/query-selector-all.js +++ b/workspaces/arborist/test/query-selector-all.js @@ -86,6 +86,9 @@ t.test('query-selector-all', async t => { dependencies: { lorem: 'latest', }, + scripts: { + test: 'tap', + }, }), }, foo: { @@ -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',