attributesComparator.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports["default"] = void 0;
  6. var _jsxAstUtils = require("jsx-ast-utils");
  7. /**
  8. * Returns true if all items in baseAttributes are found in attributes. Always
  9. * returns true if baseAttributes is empty.
  10. */
  11. function attributesComparator() {
  12. var baseAttributes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  13. var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  14. return baseAttributes.every(function (baseAttr) {
  15. return attributes.some(function (attribute) {
  16. // Guard against non-JSXAttribute nodes like JSXSpreadAttribute
  17. if (attribute.type !== 'JSXAttribute') {
  18. return false;
  19. }
  20. // Attribute matches.
  21. if (baseAttr.name !== (0, _jsxAstUtils.propName)(attribute)) {
  22. return false;
  23. }
  24. // Value exists and does not match.
  25. if (baseAttr.value && baseAttr.value !== (0, _jsxAstUtils.getLiteralPropValue)(attribute)) {
  26. return false;
  27. }
  28. return true;
  29. });
  30. });
  31. }
  32. var _default = exports["default"] = attributesComparator;
  33. module.exports = exports.default;