isNonLiteralProperty.js 1012 B

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 boolean indicating whether the given element has been specified with
  9. * an AST node with a non-literal type.
  10. *
  11. * Returns true if the elements has a role and its value is not of a type Literal.
  12. * Otherwise returns false.
  13. */
  14. var isNonLiteralProperty = function isNonLiteralProperty(attributes, propName) {
  15. var prop = (0, _jsxAstUtils.getProp)(attributes, propName);
  16. if (!prop) return false;
  17. var propValue = prop.value;
  18. if (!propValue) return false;
  19. if (propValue.type === 'Literal') return false;
  20. if (propValue.type === 'JSXExpressionContainer') {
  21. var expression = propValue.expression;
  22. if (expression.type === 'Identifier' && expression.name === 'undefined') return false;
  23. if (expression.type === 'JSXText') return false;
  24. }
  25. return true;
  26. };
  27. var _default = isNonLiteralProperty;
  28. exports["default"] = _default;