isCreateElement.js 918 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 {ASTNode} node - The AST node being checked.
  7. * @param {Context} context - 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(node, context) {
  11. const pragma = pragmaUtil.getFromContext(context);
  12. if (
  13. node.callee
  14. && node.callee.type === 'MemberExpression'
  15. && node.callee.property.name === 'createElement'
  16. && node.callee.object
  17. && node.callee.object.name === pragma
  18. ) {
  19. return true;
  20. }
  21. if (
  22. node
  23. && node.callee
  24. && node.callee.name === 'createElement'
  25. && isDestructuredFromPragmaImport('createElement', context)
  26. ) {
  27. return true;
  28. }
  29. return false;
  30. };