attributesComparator.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. } // Attribute matches.
  20. if (baseAttr.name !== (0, _jsxAstUtils.propName)(attribute)) {
  21. return false;
  22. } // Value exists and does not match.
  23. if (baseAttr.value && baseAttr.value !== (0, _jsxAstUtils.getLiteralPropValue)(attribute)) {
  24. return false;
  25. }
  26. return true;
  27. });
  28. });
  29. }
  30. var _default = attributesComparator;
  31. exports["default"] = _default;