isCreateElement.js 894 B

12345678910111213141516171819202122232425262728293031323334
  1. 'use strict';
  2. const pragmaUtil = require('./pragma');
  3. const isDestructuredFromPragmaImport = require('./isDestructuredFromPragmaImport');
  4. /**
  5. * Checks if the node is a createElement call
  6. * @param {Context} context - The AST node being checked.
  7. * @param {ASTNode} node - The AST node being checked.
  8. * @returns {boolean} - True if node is a createElement call object literal, False if not.
  9. */
  10. module.exports = function isCreateElement(context, node) {
  11. if (!node.callee) {
  12. return false;
  13. }
  14. if (
  15. node.callee.type === 'MemberExpression'
  16. && node.callee.property.name === 'createElement'
  17. && node.callee.object
  18. && node.callee.object.name === pragmaUtil.getFromContext(context)
  19. ) {
  20. return true;
  21. }
  22. if (
  23. node.callee.name === 'createElement'
  24. && isDestructuredFromPragmaImport(context, node, 'createElement')
  25. ) {
  26. return true;
  27. }
  28. return false;
  29. };