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