isCreateElement.js 893 B

123456789101112131415161718192021222324252627282930313233
  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. if (
  12. node.callee
  13. && node.callee.type === 'MemberExpression'
  14. && node.callee.property.name === 'createElement'
  15. && node.callee.object
  16. && node.callee.object.name === pragmaUtil.getFromContext(context)
  17. ) {
  18. return true;
  19. }
  20. if (
  21. node
  22. && node.callee
  23. && node.callee.name === 'createElement'
  24. && isDestructuredFromPragmaImport('createElement', context)
  25. ) {
  26. return true;
  27. }
  28. return false;
  29. };