1. 1 : import './nodeTypes';
  2. 2 :
  3. 3 :
  4. 4 : const typesMap = {
  5. 5 : '@' : 'atRule',
  6. 6 : rule: 'rule',
  7. 7 : comm: 'comment',
  8. 8 : decl: 'declaration',
  9. 9 : root: 'root',
  10. 10 : };
  11. 11 :
  12. 12 : /**
  13. 13 : * Get node type.
  14. 14 : * @memberof AST
  15. 15 : * @param {ASTNode|ASTNode[]} el Element.
  16. 16 : * @returns {?string} Node transformer name.
  17. 17 : */
  18. 18 : function getNodeType(el) {
  19. 19 : if (Array.isArray(el))
  20. 20 : return typesMap.root;
  21. 21 :
  22. 22 : const { type, } = el;
  23. 23 :
  24. 24 : if (!type)
  25. 25 : return null;
  26. 26 :
  27. 27 : return typesMap[type] ?? (type.startsWith('@')
  28. 28 : ? typesMap['@']
  29. 29 : : null);
  30. 30 : }
  31. 31 :
  32. 32 : export default getNodeType;