in src/collections/JSXElement.js [77:115]
hasAttributes: function(attributeFilter) {
const attributeNames = Object.keys(attributeFilter);
return function filter(path) {
if (!JSXElement.check(path.value)) {
return false;
}
const elementAttributes = Object.create(null);
path.value.openingElement.attributes.forEach(function(attr) {
if (!JSXAttribute.check(attr) ||
!(attr.name.name in attributeFilter)) {
return;
}
elementAttributes[attr.name.name] = attr;
});
return attributeNames.every(function(name) {
if (!(name in elementAttributes) ){
return false;
}
const value = elementAttributes[name].value;
const expected = attributeFilter[name];
// Only when value is truthy access it's properties
const actual = !value
? value
: Literal.check(value)
? value.value
: value.expression;
if (typeof expected === 'function') {
return expected(actual);
}
// Literal attribute values are always strings
return String(expected) === actual;
});
};
},